在数组数组中获取json响应

时间:2017-12-07 06:57:56

标签: android arrays json

我的Json响应如下。我想从静态网站,动态网站等响应中获取单个数组项。你能帮帮我吗?

{
  "data": [
    [
      "Static Website"
    ],
    [
      "Dynamic Website"
    ],
    [
      "E-Commerce Website"
    ],
    [
      "ERP"
    ],
    [
      "IOS Application"
    ],
    [
      "Social Networking"
    ],
    [
      "Web Application"
    ],
    [
      "Graphic Design"
    ]
  ],
  "status": 200
}

3 个答案:

答案 0 :(得分:0)

试试这个代码段

 @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();

            }
        }

答案 1 :(得分:0)

试试这个

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();

}

答案 2 :(得分:0)

试试这个。

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();

    }
}