如何从Json数组中的Json数组中解析和获取数据?

时间:2017-09-13 10:33:13

标签: android arrays json

{
"images": [
    [
        2,
        "91/914fbbb8694ba1865b7bf3da0cc7ec512a0630dcf16c3f8347b6b4d3.png",
        760,
        3910
    ],
    [
        1,
        "6c/6c9f754578229fb925cb80033cced89ff3ff56795fc50899d3718725.png",
        760,
        5242
    ],
    [
        0,
        "44/446c0ce1047fd617ee086aaa21277229f21b0d29a753c8e3a0df8ca0.png",
        760,
        1080
    ]
]}

**需要访问Images数组中每个数组内的数据...如何将这些数据放入数组列表**

2 个答案:

答案 0 :(得分:1)

试试这个

 ArrayList<String> arrayList = new ArrayList<>();
 JSONObject jsonObject= new JSONObject("response");
 JSONArray myArray = jsonObject.optJSONArray("images");;

 for (int j = 0; j < myArray.length(); j++) {
    try {
          JSONArray jsonarray = myArray.optJSONArray(j);
          for (int i = 0; i < jsonarray.length(); i++){
              String data = jsonarray.getString(j);
              Log.e("PHOTOS_URL", i + "=" + data);
              arrayList.add(data);
           }

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

  }

答案 1 :(得分:1)

假设你有jsonResponse是响应

然后SELECT ROW_NUMBER() OVER (ORDER BY rv.Timestamp DESC) AS Rows, rv.Timestamp, c.Description, rv.Value, rv.Deltavalue, c.Tag, (LEAD(rv.Value_num) OVER (ORDER BY rv.Timestamp) - rv.Value_num) as diff FROM dbo.Channels c INNER JOIN (SELECT rv.*, TRY_CONVERT(numeric(20, 4), rv.value) as value_num FROM dbo.RecordedValues rv ) rv ON c.SourceId = rv.SourceId AND c.SourceId = rv.ChannelId WHERE c.Description LIKE N'%AL Electra%';

然后JSONObject jsonObject = new JSONObject(responce);

然后:

JSONArray imagejsonArray=jsonObject.optJSONArray("images");

现在对象json数组是你解析的最后一个jsonarray