-1

My Json response is as follows.I want to get the individual array item from the response like static website,dynamic website.Can you help me please?

{
  "data": [
    [
      "Static Website"
    ],
    [
      "Dynamic Website"
    ],
    [
      "E-Commerce Website"
    ],
    [
      "ERP"
    ],
    [
      "IOS Application"
    ],
    [
      "Social Networking"
    ],
    [
      "Web Application"
    ],
    [
      "Graphic Design"
    ]
  ],
  "status": 200
}
Dhruv Patel
  • 1,529
  • 1
  • 18
  • 27
bini
  • 17
  • 9

3 Answers3

0

Try this snippet

 @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);

            try {
                JSONArray jsonArray = response.getJSONArray("data");
                String status = response.getString("status");

                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObject = (JSONObject) jsonArray.get(i);
                   //get Whatever you want here and add to arraylist or store somewhere//
                }
            }
            catch (JSONException e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), R.string.exception, Toast.LENGTH_SHORT).show();

            }
        }
Community
  • 1
  • 1
Aqua 4
  • 771
  • 2
  • 9
  • 26
0

Try this

JSONObject jsonObject=new JSONObject("Your Json String");

try {
       JSONArray jsonArray = jsonObject.getJSONArray("data");
       String status = jsonObject.getString("status");
       Log.d("Status","Status"+ status);

       for (int i = 0; i < jsonArray.length(); i++) {
           JSONArray jsonArray1 = (JSONArray) jsonArray.get(i);
            Log.d("Value", "Json Array Value" + jsonArray1);
       }
} catch (JSONException e) {
   e.printStackTrace();

}
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
0

Try this One.

public void parseJsonResponse(JSONObject jsonObject) {
    try {
        JSONArray jsonArray = jsonObject.getJSONArray("data");
        String status = jsonObject.getString("status");
        Log.d("StatusCode", "Status" + status);

        for (int i = 0; i < jsonArray.length(); i++) {
            JSONArray jsonarrayInner = (JSONArray) jsonArray.get(i);
            Log.d("", "JsonArray Value" + jsonarrayInner);

            for (int j = 0; j < jsonarrayInner.length(); j++) {
                String s1 = jsonarrayInner.getString(j);

            }
        }
    } catch (JSONException e) {
        e.printStackTrace();

    }
}
Dharmishtha
  • 1,313
  • 10
  • 21