当前位置: 代码迷 >> Android >> 在java中获取数组json中的数组值
  详细解决方案

在java中获取数组json中的数组值

热度:64   发布时间:2023-08-04 11:49:20.0

我需要获取数组“ q1”的值,该数组在数组“问题”中,数组是json,我需要Java android中的值。

{
    "questions": [
        {
            "q1": [
                "what my name?",
                "a",
                "b",
                "c",
                "Mac"
            ],
            "q2": [
                "what my age?",
                "1",
                "34",
                "80",
                "3"
            ]
        }
    ]
}

在这里,我正在回答您的问题以解决您的问题,但我的朋友您需要首先学习有关json解析的知识。

建议:您可以在这里找到示例:

答:

JSONObject jresonseobj = response.getjObj();
JSONObject jobj;
JSONArray jsonArray = new JSONArray(jresonseobj.getString("questions"));

for (int i = 0; i < jsonArray.length(); i++) 
{
        jobj = jsonArray.getJSONObject(i);
        // parse inner json here.  
}