我将所有朋友的信息(例如姓名,位置等)作为图形对象作为响应,但是当我想从 json 获取位置时,它给了我任何位置的价值。请帮助我并告诉我我在哪里做错了?
Bundle required = new Bundle();
required.putString("fields", "id,name,picture,location,locale,gender,email");
Request req = new Request(session, "me/friends", required,HttpMethod.GET,
new Callback() {
@Override
public void onCompleted(Response response){
GraphObject is=response.getGraphObject();
// Log.w("FriendsList", is.toString());
String location="";
if (is != null) {
JSONObject jsonObject = is.getInnerJSONObject();
try {
JSONArray myfriendlist=new JSONArray();
JSONArray array = jsonObject.getJSONArray("data");
for (int i = 0; i < array.length(); i++) {
JSONObject object = (JSONObject) array.get(i);
JSONObject friendlist = new JSONObject();
JSONObject keyfriendlist = new JSONObject();
JSONArray loc = jsonObject.getJSONArray("location");
for(int j=0;j<loc.length();j++){
location=object.get("id").toString();
if(location==null||location==""||location=="null")
{
continue;
}}
LOGCAT
04-18 18:48:37.360: W/System.err(28862): org.json.JSONException: No value for location
04-18 18:48:37.365: W/System.err(28862): at org.json.JSONObject.get(JSONObject.java:354)
04-18 18:48:37.365: W/System.err(28862): at org.json.JSONObject.getJSONArray(JSONObject.java:544)
04-18 18:48:37.365: W/System.err(28862): at com.example.socialize_us.MainFragment$2.onCompleted(MainFragment.java:106)
04-18 18:48:37.365: W/System.err(28862): at com.facebook.Request$4.run(Request.java:1240)
04-18 18:48:37.365: W/System.err(28862): at android.os.Handler.handleCallback(Handler.java:605)
04-18 18:48:37.365: W/System.err(28862): at android.os.Handler.dispatchMessage(Handler.java:92)
04-18 18:48:37.365: W/System.err(28862): at android.os.Looper.loop(Looper.java:137)
04-18 18:48:37.365: W/System.err(28862): at android.app.ActivityThread.main(ActivityThread.java:4666)
04-18 18:48:37.365: W/System.err(28862): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 18:48:37.366: W/System.err(28862): at java.lang.reflect.Method.invoke(Method.java:511)