JSON ARRAY decoding in android
I am in a problem with a json array. I have got this form server(php) end
and unable to decode this uisng android(java). Can you please help me
anyway?
JSON:{"status":"success","message":[{"name":"abc abc
abc","new_book_id":"49","h_p_y":"8 iso, new 345,
1234","comment":"1","rating":5,"image_link":"http:\/\/www.yahoo.com\/cou\/images\/view.jpg","comment_array":[{"com":"good
like","name":"android"}]},{"name":"cdb
cdbcdv","new_book_id":"1234","h_p_y":"345
wert","comment":"1","rating":3,"image_link":"http:\/\/www.yahoo.com\/cou\/images\/view.jpg","comment_array":[{"com":"I
took my wife for her first ever swim. great value for the price
","name":"Guest User"},{"com":"","name":"Guest User"}]},,"totalsize":10}
I can't able to get elements (com, name) from comment array.
I am trying this to decode in android end:
row = new JSONObject(jsonResult);
data = row.getJSONArray("message");
for (int i = 0; i < data.length(); i++) {
HashMap<String, String> storeValues = new HashMap<String, String>();
row = data.getJSONObject(i);
data1 = row.getJSONArray("comment_array");
for(int k=0;k<data1.length();k++){
Toast.makeText(getApplicationContext(), "hellow"+k,
Toast.LENGTH_SHORT).show();
}
storeValues.put(NAME, row.getString("name"));
storeValues.put(ABC,row.getString("h_p_y"));
storeValues.put(IMAGE_URL, row.getString("image_link"));
storeValues.put(RATING,row.getString("rating"));
storeValues.put(COMMENT,row.getString("comment"));
storeValues.put(new_book_id,row.getString("new_book_id"));
}
Thanks in advance.
No comments:
Post a Comment