Android从facebook json获取数据

Android从facebook json获取数据,android,json,facebook,facebook-graph-api-v2.0,Android,Json,Facebook,Facebook Graph Api V2.0,我从facebook得到了这样的回应。 如何得到名字 我累了 {Response: responseCode: 200, graphObject: {"id":"108303252910226","first_name":"Chris","last_name":"Jack","email":"adaptech123@gmail.com","gender":"male","birthday":"08\/08\/1984","hometown":{"id":"106377336067638","n

我从facebook得到了这样的回应。 如何得到名字

我累了

{Response:  responseCode: 200, graphObject: {"id":"108303252910226","first_name":"Chris","last_name":"Jack","email":"adaptech123@gmail.com","gender":"male","birthday":"08\/08\/1984","hometown":{"id":"106377336067638","name":"Bangalore, India"}}, error: null}

在GraphRequest方法中

 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();
                            }

这是一个多维数组,所以首先要将该数组拆分

GraphRequest request = GraphRequest.newMeRequest(
                                loginResult.getAccessToken(),
                                new GraphRequest.GraphJSONObjectCallback() {
                                    @Override
    public void onCompleted(JSONObject object,GraphResponse response) {
         object.getString("first_name")
    }
});
String res=“[”+”{responseCode:200,图形对象:{“id”:“108303252910226”,“名字”:“Chris”,“姓氏”:“Jack”,“email”:”adaptech123@gmail.com“,”性别“:”男性“,”生日“:”08\/08\/1984“,”家乡“:{”id“:”106377336067638“,”姓名“:”印度班加罗尔“}}”,错误:null}”+“]”;
JSONObject c;
JSONArray数据=null;
试一试{
数据=新的JSONArray(res);
}捕获(JSONException e1){
e1.printStackTrace();
}  
试一试{
如果(数据!=null){
对于(int i=0;i

然后用dd字符串对json进行编码。

到目前为止您做了什么?发布您的代码了解json对象以及如何使用它。这可能会对您有所帮助
String res="["+"{responseCode: 200, graphObject: {"id":"108303252910226","first_name":"Chris","last_name":"Jack","email":"adaptech123@gmail.com","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")
                      }