I'm developing an Android application, I have to implement a function that parse my JSON and return to me certain result.
For example, I have a JSON with this strcutures:
[
{
"date":"17-06-2016",
"desc":"My description",
"id":"9",
"img":"http:\/\/myurl\/pathimage\/image.jpg",
"text":"Lorem Ipsum.",
"title":"My title"
}, {
"date":"14-06-2015",
"desc":"My description 2",
"id":"5",
"img":"http:\/\/myurl\/pathimage\/image.jpg",
"text":"Lorem Ipsum 2.",
"title":"My title 2"
}
]
I need to select ONLY the object with id = 9, how i can do this ? How i can select programmatically the JSON object discriminating respect the id ?
I know how to parse JSON, but i DON'T know how to select programmatically the JSON object discriminating respect the id.
****** EDIT 1 ******
JSONArray newsReq;
try {
newsReq = new JSONArray(result.toString());
for (int i = 0; i < newsReq.length(); i++) {
try {
if(obj.getInt("id")=='9'){
JSONObject obj = newsReq.getJSONObject(i);
obj.getString("img");
obj.getInt("id");
obj.getString("title");
}
} catch (JSONException e) {
Log.wtf("BulgariLog: ", e);
}
}
} catch (JSONException e) {
Log.wtf("BulgariLog: ", e);
}