I have a JSON string like this which is received from a server:
[{"AdsId":"7","AdsName":"PIC_01.JPG","AdsImage":"pic_01.jpg","AdsImageUrl":"http://www.google.com","TargetUrl":"http://www.yahoo.com","IsAllPageSupport":false,"IsArabic":false,"IsActive":true},{"AdsId":"8","AdsName":"PIC_02.JPG","AdsImage":"pic_02.jpg","AdsImageUrl":"http://www.fb.com","TargetUrl":"http://www.twitter.com","IsAllPageSupport":true,"IsArabic":false,"IsActive":true},{"AdsId":"9","AdsName":"PIC_03.JPG","AdsImage":"pic_03.jpg","AdsImageUrl":"http://www.google.com","TargetUrl":"http://www.demo.com","IsAllPageSupport":false,"IsArabic":false,"IsActive":true},{"AdsId":"10","AdsName":"PIC_04.JPG","AdsImage":"pic_04.jpg","AdsImageUrl":"http://www.sample.com","TargetUrl":"http://www.example.com","IsAllPageSupport":true,"IsArabic":false,"IsActive":true}]
This is a valid JSON format. But I don't know how to parse this string and retrieve the values inside this JSON string.
I'm using this code for parsing the JSON array. But this code is used for retrieving values from a JSON array, and I don't know how to get values from the above received JSON string.
JSONObject jsonResponse;
try {
jsonResponse = new JSONObject(status);
JSONArray jsonMainNode = jsonResponse.optJSONArray("Android");
int lengthJsonArr = jsonMainNode.length();
Log.d("Json Array Length of status",String.valueOf(lengthJsonArr));
for(int j1=0; j1 < lengthJsonArr; j1++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(j1);
String addstatus=jsonChildNode.optString("slno").toString();
}
} catch(Exception ex) {
ex.printStackTrace();
}