JSON может быть более 2 пункта или меньше. Максимум 8 пункта, 8 часов.
Я делаю запрос PHP в моем приложении, отправьте данные, которые выполняют запуск запроса, результат - результат JSON. < /P>
Вот мой код: < /p>
Код: Выделить всё
try {
post.setEntity(new UrlEncodedFormEntity(dataToSend)); //post the datas for the query
HttpResponse httpResponse = client.execute(post);
HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity);
JSONObject jObject = new JSONObject(result);
JSONArray jArr = jObject.getJSONArray("dates");
if (jObject.length() != 0) {
for (int i = 0; i < jArr.length(); i++)
{
String[] dates = jArr.getJSONObject(i).getString("dates");
/*Here I don't really have idea what to do
I want a String array which indexes are the result hours
like dates[0] = "13:00:00"*/
}
< /code>
и php: < /p>
$place = $_POST["place"];
$date = $_POST["date"];
$sql = "SELECT appointment FROM dates WHERE place = '$place' AND appointment LIKE '%$date%' ";
$result = mysqli_query($con, $sql);
$datehours = array();
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
array_push($datehours, $row["appointment"]); //after it datehours like [0] => 2016-04-08 13:00:00
}
$dates = array();
foreach($datehours as $x => $x_value) {
$muvelet = explode(" ",$x_value); //here I select from the timeststamp only the hours
array_push($dates, $muvelet[1]); //$date like [0] => 13:00:00
}
echo json_encode($dates, JSON_UNESCAPED_UNICODE); //the encode is ["13:00:00","14:00:00"]
Код: Выделить всё
$date["firsthour"] => 13:00:00Подробнее здесь: https://stackoverflow.com/questions/360 ... ith-arrays
Мобильная версия