如何从下面的字符串中获取值fan_count
,第一 message
和created_time
。
我已尝试过下面的代码,但显然不起作用:
facebook_Fan_Count = queryResults.get(0).getString("fan_count");
facebook_post = queryResults.get(0).getString("message");
字符串:
{
"data": [
{
"name": "count",
"fql_result_set": [
{
"fan_count": 732
}
]
},
{
"name": "messages",
"fql_result_set": [
{
"message": "Weekly class with Sheikh Hassan on TILAWA \n(implementing tajweed)\n\nEvery Friday after Maghreb\nCommencing 6th December at Daar Ibn Abbas.",
"timeline_visibility": "normal",
"created_time": 1386230874
},
{
"message": "SMS SERVICE:\n\nTo keep up to date with events and prayer times at Daar Ibn Abbas please inbox us your name and number.\n\nJazackAllah khier",
"timeline_visibility": "starred",
"created_time": 1386022521
}
]
}
]
}
答案 0 :(得分:0)
要提取fan_count,1st message和created_time的值,你可以进行Json解析
JSONArray ar = (JSONArray) jsonObject.get("data");
您可以遍历此数据并获取第一条消息
从第一次迭代中你可以获得fan_count
jsonObject = (JSONObject) ar.get(0);
fan_count 不是字符串,类型为long。
所以你需要做这样的事情
long count = (Long) jsonObject.get("fan_count");
从第二次迭代中,您可以获得消息并创建日期
jsonObject = (JSONObject) ar.get(1);
String message = (String) obj1.get("message");
long dt = (Long) obj1.get("created_time");