我正在使用Facebook的Graph API,而我正试图获得比表面更强的JSON对象。我该怎么做呢?
JSON对象如下所示:
{
"id": "#############",
"name": "Page Name",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/hprofile-xap1/v/t1.0-1/p50x50/76818_139533536097297_144033_n.jpg?oh=9caa264df8b15feb6ecdjeajks9d43ee05bc22&oe=5750EE78"
}
}
}
(该网址不是此示例的真实网址)
我试过这个:
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
facebook_name.setText("Logged in as " + object.optString("name"));
try {
JSONArray pictureArray = object.getJSONArray("picture");
for (int i = 0; i < pictureArray.length(); i++) {
JSONObject picture = pictureArray.getJSONObject(i);
JSONArray pictureDataArray = picture.getJSONArray("data");
for (int j = 0; j < pictureDataArray.length(); j++) {
JSONObject pictureData = pictureDataArray.getJSONObject(j);
String pictureDataURL = pictureData.optString("url");
Log.d("*******************", pictureDataURL);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
但我没有得到我的Log.d
。我错误地穿越了这个吗?有更简单的方法吗?
答案 0 :(得分:0)
我找到了答案。我只需要在.getJSONObject()
上保持字符串以保持低位以找到我正在寻找的内容:
String pictureURL = object.getJSONObject("picture").getJSONObject("data").getString("url");