Here is my json structure:
[{"id":"112","image_data":"http:\/\/elogistic.890m.com\/images\/111.png","image_tag":"232188933"},{"id":"113","image_data":"http:\/\/elogistic.890m.com\/images\/112.png","image_tag":"232188933"},{"id":"114","image_data":"http:\/\/elogistic.890m.com\/images\/113.png","image_tag":"232188933"}]
How can I get String "image_data" for each object per String ? example :
String 1 = "image_data"of object1
String 2 = "image_data"of object2
Thanks so much
Zoe - Save the data dump
28.4k22 gold badges130 silver badges164 bronze badges
1 Answer 1
Try below code. this the example of getting an imagedata from your response you need to modify it as per your requirements
try {
JSONArray jsonArray = new JSONArray(Your Json Array String);
ArrayList<String> imgData = new ArrayList<>();
for (int i=0; i<jsonArray.length();i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
imgData.add(jsonObject.getString("image_data"));
}
String imgData1 = imgData.get(0);
String imgData2 = imgData.get(1);
} catch (JSONException e) {
e.printStackTrace();
}
answered Nov 26, 2017 at 16:24
Munir
2,5581 gold badge14 silver badges20 bronze badges
Sign up to request clarification or add additional context in comments.
6 Comments
user7931784
Thanks you so much ..!
Munir
@user7931784 happy to help you.
Munir
@user7931784 if answer helped you then you may accept it as right
user7931784
When I toast img1 , it including "image_data" of object 2 , how to separate it , my mean hear is , how to get , String img1 = "image_data" of Object 1 and String img2 = "image_data" of Object 2 . thanks for advise
Munir
@user7931784 see my updated answer
|
default