如何从无名的Json数组中获取价值

时间:2015-01-27 10:47:13

标签: android

String  Result=GET(url);
Log.e("result", "data" + Result);
try{
    //JSONObject jsonResponse = new JSONObject(Result);
    // JSONArray jsonMainNode = jsonResponse.optJSONArray();
    //int len= jsonMainNode.length();
    JSONArray jsonarray = new JSONArray(Result);

    for (int i = 0; i < 3; i++) {
        JSONObject jsonobj = jsonarray.getJSONObject(i);

        System.out.println("categoryId : " + i + " = " + jsonobj.getString("FirstName"));
        System.out.println("Title : " + i + " = " + jsonobj.getString("LastName"));
        //System.out.println("songs : " + i + " = " + jsonobj.getString("songs"));
    }

注意:我正在尝试使用无名数组的对象。我没有得到如何将响应存储为Json对象的形式

1 个答案:

答案 0 :(得分:0)

试试这个对我有用。

try {
    JSONArray jarr = new JSONArray(Result);
    for (int i = 0; i < jarr.length(); i++) {
        JSONObject jsonobj= jarr.getJSONObject(i);
        System.out.println("categoryId : " + i + " = " + jsonobj.getString("FirstName"));
        System.out.println("Title : " + i + " = " + jsonobj.getString("LastName"));

    }
}