首页 > 解决方案 > 我想阅读此 JSON 行,但因为它以 JSONObject 和 JsonArray 开头

问题描述

我只需要从下面的答案中保存第一个Table:[]行,例如在 Android Studio 的表布局中显示(获取字符串)值。请提供任何其他方式从以下代码中获取此详细信息,我在 http 请求中给出

{
    "Result": {
        "resultsrow": [
            {
                "RowError": "",
                "RowState": 2,
                "Table": [
                    {
                        "refno": "09127178888",
                        "name": "S Santhosh kumar",
                        "address": "qwerty",
                        "mobile": 123456789,

                    },
                    {
                        "refno": "0912717999999",
                        "name": "ggg",
                        "address": "gggttr54",
                        "mobile": 2134567890,

                    }
                ],
                "ItemArray": [
                    "091271788888",
                    "S Santhosh kumar",
                    "qwerty1",
                    1234567890,

                ],
                "HasErrors": false
            },
            {
                "RowError": "",
                "RowState": 2,
                "Table": [
                    {
                        "refno": "091271788888",
                        "name": "S Santhosh kumar",
                        "address": "qwerty",
                        "mobile": 1234567890,

                    },
                    {
                        "refno": "091271799999",
                        "name": "ggg",
                        "address": "gggttr54, ",
                        "mobile": 2134567890,

                    }
                ],
                "ItemArray": [
                    "0912717999999",
                    "ggg",
                    "gggttr54, ",
                    2134567890,

                ],
                "HasErrors": false
            }
        ]
    },
    "Message": "",
    "Success": true
}

标签: android

解决方案


请使用这个,这对你有用

   try {
        JSONObject j= new JSONObject(YourJsonString);
        JSONObject result= (JSONObject) j.get("Result");
        JSONArray resultsrowArray=result.getJSONArray("resultsrow");
        for (int i = 0; i < resultsrowArray.length(); i++) {
            JSONObject arrayObject= resultsrowArray.getJSONObject(i);
            String RowError=arrayObject.getString("RowError");
            int RowState=arrayObject.getInt("RowState");
            JSONArray ItemArray=arrayObject.getJSONArray("ItemArray");
            for (int i1 = 0; i1 < ItemArray.length(); i1++) {
                String item1= ItemArray.getString(i1);


            }
        }

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

推荐阅读