-1

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

0

1 Answer 1

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();
        }
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks you so much ..!
@user7931784 happy to help you.
@user7931784 if answer helped you then you may accept it as right
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
@user7931784 see my updated answer
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.