1

I am having this in JSONArray ary2;

JSON string is :

[
      {
        "item_id": "1",
        "Head_item_id": "1",
        "major_item_id": "1",
        "Quantity": "10",
        "selling_prize": "20",
        "MRP": "90",
        "title": "JK Lakshmi PPC Cement",
        "SKU": "B2WBUICEM2"
      },
      {
        "item_id": "2",
        "Head_item_id": "1",
        "major_item_id": "1",
        "Quantity": "10",
        "selling_prize": "30",
        "MRP": "80",
        "title": "JK Lakshmi PPC Cement",
        "SKU": "B2WBUICEM2"
      },
      {
        "item_id": "3",
        "Head_item_id": "1",
        "major_item_id": "1",
        "Quantity": "10",
        "selling_prize": "10",
        "MRP": "70",
        "title": "Shree Ultra OPC 43 Grade Cement",
        "SKU": "B2WBUICEM5"
      }
      ]

I want to get String array for each attribute , like :

String[] item_id;
String[] Head_item_id; 

etc. unable to get it. Please help.

0

2 Answers 2

1

Try This:

JSONArray arr = new JSONArray(yourJSONresponse);
String[] item_id=new String[array.length()];
String[] Head_item_id=new String[arr .length()];
for(int i = 0; i < arr.length(); i++){
    item_id[i]=arr.getJSONObject(i).getString("item_id");
    Head_item_id[i]=arr.getJSONObject(i).getString("Head_item_id");
}
Sign up to request clarification or add additional context in comments.

Comments

1

You need to follow these steps: -> Create POJO for your JSON data and provite getters and setters for each attribute. -> Parse your JSON data using GSON -> get the desired attribute(using getters) and store it in the respective string array

1 Comment

Try to follow any json parsing tutorial using gson

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.