2016-05-03 2 views
-2
{Response: responseCode: 200, graphObject: {"id":"108303252910226","first_name":"Chris","last_name":"Jack","email":"[email protected]","gender":"male","birthday":"08\/08\/1984","hometown":{"id":"106377336067638","name":"Bangalore, India"}}, error: null} 

Я получаю этот ответ от facebook. как получить имяAndroid, получающий данные от facebook json

Я устал

try { 
           String res = response+""; 
           JSONObject j = new JSONObject(res); 
           String graphResponse = j.optString("graphObject"); 

           JSONObject j2 = new JSONObject(graphResponse); 

           String first_name = j2.getString("first_name"); 

           Log.i("firstname", ""+first_name); 
          } 
          catch (JSONException e) 
          { 
           e.printStackTrace(); 
          } 
+1

Что вы сделали до сих пор? разместите свой код –

+0

Понимайте объект json и как его использовать, http://developer.android.com/intl/zh-tw/reference/org/json/JSONObject.html. –

+0

Это может быть полезно вам http://stackoverflow.com/questions/30317540/how-do-i-fetch-name-and-email-using-facebook-sdk –

ответ

0

внутри метода GraphRequest

GraphRequest request = GraphRequest.newMeRequest(
           loginResult.getAccessToken(), 
           new GraphRequest.GraphJSONObjectCallback() { 
            @Override 
    public void onCompleted(JSONObject object,GraphResponse response) { 
     object.getString("first_name") 
    } 
}); 
0

Это многомерный массив, так что вы первый пролил этот массив.

String res="["+"{responseCode: 200, graphObject: {"id":"108303252910226","first_name":"Chris","last_name":"Jack","email":"[email protected]","gender":"male","birthday":"08\/08\/1984","hometown":{"id":"106377336067638","name":"Bangalore, India"}}, error: null}"+"]"; 
      JSONObject c; 
      JSONArray data=null; 
      try { 
       data = new JSONArray(res); 
      } catch (JSONException e1) { 
       e1.printStackTrace(); 
      } 
     try { 
     if(data != null) { 
       for (int i = 0; i < data.length(); i++) { 
        c = data.getJSONObject(i); 
        String lat=c.getString("responseCode"); 
        JSONArray dd=  c.getJSONArray("graphObject") 
         } 

then json encode with dd string.