您好我是Android开发的新手,我想从json数组中提取值,请您指导。
这是我的json
[
{
"Id": "c0f3310b-5ec2-4af0",
"UserId": "fd83ca17-41f5-472a",
"ProfileId": "100006690",
"ProfileType": "facebook",
"ProfileDate": "/Date(1380894956000)/",
"ProfileStatus": 1
},
{
"Id": "6954433d-b78e-47b6",
"UserId": "fd83ca17-41f5-8efe",
"ProfileId": "100004492",
"ProfileDate": "/Date(1380894685000)/",
"ProfileStatus": 1,
"ProfileType": "facebook"
}
]
谢谢
答案 0 :(得分:0)
如下面的编码
JSONArray jObject = new JSONArray(jsoninputstring);
for (int i = 0; i < jObject.length(); i++) {
JSONObject obj = jObject.getJSONObject(i);
String name= obj.getString("Id");
String email= obj.getString("UserId");
String image= obj.getString("ProfileId");
}
以下是JSON解析的教程
http://www.androidhive.info/2012/01/android-json-parsing-tutorial/
答案 1 :(得分:0)
创建新的JSONArray对象并迭代它。
JSONArray arr = new JSONArray(jsonString);
for(int i=0;i<arr.length;i++){
JSONObject obj = arr.getJSONObject(i);
// read data from obj using obj.getString method.
}
答案 2 :(得分:0)
JSONArray categories = responseData.getJSONArray("categories"); // your JSON array
for(int i=0; i < categories.length(); i++){
JSONObject ob = (JSONObject) categories.get(i);
ob.getString("Id");
ob.getString("UserId"); // and so on
}
答案 3 :(得分:0)
我强烈建议您查看JacksonParser ...您可以从this link下载jar文件,您可以轻松找到如何使用它的示例。这是将json解析为对象的最简单,最快捷的方法。
答案 4 :(得分:0)
JSONArray jsonArray = new JSONArray(yourResponseString);
for(int i=0;i<jsonArray.length();i++){
JSONObject dataObject=dataArray.getJSONObject(i);
String ID=dataObject.getString("Id");
String UserID=dataObject.getString("UserId");
String ProfileID = jsonObject.getString("ProfileId");
..
}