In my app I need to obtain some data from server. In eclipse I receive data like this :
[{"id_category":"1","category_name":"Cool"},{"id_category":"2","category_name":"Glamor"},{"id_category":"3","category_name":"Funky"},{"id_category":"4","category_name":"Crazy"},{"id_category":"5","category_name":"David Guetta"}] without any name.
I tried something like this :
if (response != null) {
responseBody = EntityUtils.toString(response.getEntity());
System.out
.println("Rezultat de la server pentru a afla categoriile:"
+ responseBody);
try {
final String r = response.toString();
String name = json.getString("category name");
System.out.println("One category"+name);
} catch (JSONException e) {
// do nothing
} catch (FacebookError e) {
e.getMessage();
}
but nothing happens. How can I get id_category and category_name from my response?
Can anyone help me? Thanks in advance.
This is how you parse JSON…I hope it works.