i'm developing an android project which i need to create a JSON message in my php server and send it to the android devices.
i wrote the following code in php
$event_array = array();
// fill the event_array with some data
print json_encode(array('event_array' => $event_array));
but the result is like
{
"event_array": {
"id_1": {
"name": "name",
"logo_address": "logo_address",
"title": "title",
"time": null,
"address": null,
"address_location": null,
"explain": null,
"type": null,
"id": "id_1",
"number_of_users": null
},
"id_2": {
"name": "name2",
"logo_address": null,
"title": null,
"time": null,
"address": null,
"address_location": null,
"explain": null,
"type": null,
"id": "id_2",
"number_of_users": null
}
}
}
and it's not a json array and i get exception in my android code which simply is
JSONObject jObject = new JSONObject(res);
JSONArray jArray = jObject.getJSONArray("event_array");
what's wrong?
thanks for any help