android 嵌套JSON解析 10
求指点如何取出下面各个name下的信息,感激!{"id":"100005065353669","likes":{"data":[{"category":"Musician...
求指点如何取出下面各个name下的信息,感激!
{
"id": "100005065353669",
"likes": {
"data": [
{
"category": "Musician/band",
"name": "Jay Chou",
"id": "109155665769390",
"created_time": "2013-06-11T18:54:44+0000"
},
{
"category": "Musician/band",
"name": "Eason Chan",
"id": "105468519487919",
"created_time": "2013-06-05T20:33:26+0000"
},
{
"category": "Product/service",
"name": "Facebook Developers",
"id": "19292868552",
"created_time": "2013-05-31T01:35:17+0000"
}
],
"paging": {
"next": "https://graph.facebook.com/100005065353669/likes?limit=5000&offset=5000&__after_id=19292868552"
}
}
}
由于我在尝试开发一个facebook相关的android软件,用到facebook的SDK,所以和一般的可能有所不同,如以下的JSON
{
"languages": [
{
"id": "111735208843636",
"name": "Chinese"
},
{
"id": "106059522759137",
"name": "English"
}
],
"id": "100005065353669"
}
我的解析name的代码是
JSONArray languages = (JSONArray)user.getProperty("languages");
if (languages.length() > 0) {
ArrayList<String> languageNames = new ArrayList<String> ();
for (int i=0; i < languages.length(); i++) {
JSONObject language = languages.optJSONObject(i);
languageNames.add(language.optString("name"));
}
userInfo.append(String.format("Languages: %s\n\n", languageNames.toString()));
}
这里的user来自private String buildUserInfoDisplay(GraphUser user) 展开
{
"id": "100005065353669",
"likes": {
"data": [
{
"category": "Musician/band",
"name": "Jay Chou",
"id": "109155665769390",
"created_time": "2013-06-11T18:54:44+0000"
},
{
"category": "Musician/band",
"name": "Eason Chan",
"id": "105468519487919",
"created_time": "2013-06-05T20:33:26+0000"
},
{
"category": "Product/service",
"name": "Facebook Developers",
"id": "19292868552",
"created_time": "2013-05-31T01:35:17+0000"
}
],
"paging": {
"next": "https://graph.facebook.com/100005065353669/likes?limit=5000&offset=5000&__after_id=19292868552"
}
}
}
由于我在尝试开发一个facebook相关的android软件,用到facebook的SDK,所以和一般的可能有所不同,如以下的JSON
{
"languages": [
{
"id": "111735208843636",
"name": "Chinese"
},
{
"id": "106059522759137",
"name": "English"
}
],
"id": "100005065353669"
}
我的解析name的代码是
JSONArray languages = (JSONArray)user.getProperty("languages");
if (languages.length() > 0) {
ArrayList<String> languageNames = new ArrayList<String> ();
for (int i=0; i < languages.length(); i++) {
JSONObject language = languages.optJSONObject(i);
languageNames.add(language.optString("name"));
}
userInfo.append(String.format("Languages: %s\n\n", languageNames.toString()));
}
这里的user来自private String buildUserInfoDisplay(GraphUser user) 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询