JSON对象解析文本和图像

时间:2012-05-02 14:35:10

标签: android json parsing

我正在尝试解析httpResponse返回的以下JSON字符串:

{ "message" : "List of top ten checkin Men.",
  "success" : "True",
  "top_ten_checkin_men" : [ { "City_name" : "Mumbai",
        "is_block" : "no",
        "is_favorite" : "no",
        "is_friend" : "no",
        "last_step_in" : "Pride Hotels",
        "online" : "1",
        "points" : "3800",
        "request_pending" : "no",
        "user_thumbphoto" : "",
        "userage" : "26",
        "userbodytype" : "3",
        "userfname" : "John",
        "usergender" : "Male",
        "userid" : "191",
        "userlname" : "Aarmani",
        "userlookingfor" : "Female",
        "useronlinestatus" : "Yes",
        "userphoto" : ""
      },
      { "City_name" : "New York",
        "is_block" : "no",
        "is_favorite" : "no",
        "is_friend" : "no",
        "last_step_in" : "The House of MG",
        "online" : "1",
        "points" : "4450",
        "request_pending" : "no",
        "user_thumbphoto" : "http://anburaj.com/lockme/uploads/users/188/thumb_121840970.jpg",
        "userage" : "31",
        "userbodytype" : "3",
        "userfname" : "Williams",
        "usergender" : "Male",
        "userid" : "188",
        "userlname" : "Johens",
        "userlookingfor" : "Female",
        "useronlinestatus" : "Yes",
        "userphoto" : "http://anburaj.com/lockme/uploads/users/188/121840970.jpg"
      }
    ]
}

等等。

我应该为jsonarray采取什么以及jsonobject应该采取什么措施?

3 个答案:

答案 0 :(得分:3)

[]定义JSONArray(例如top_ten_checkin_men)。 {}定义了JSONObject

值得花点时间了解JSON格式here

http://json.org/array.gif

enter image description here

答案 1 :(得分:1)

“[]”表示数组,“{}”表示对象

答案 2 :(得分:1)

这里有一个JSONObject,其中包含成功和消息字段以及JSONArray top_ten_checkin_men

类似于:

JSONObject json = new JSONObject(yourString);
String message = json.getString("message");
String success = json.getString("success");
JSONArray array = json.getJSONArray("top_ten_checkin_men");

应该做你想做的事情