Question

I have developed an application that have facebook functionality and other is grtting users friend list and their birth date for notify in future but when i am going to fetch those data using Facebook SDK its show error:JSON Error in responseValue

my code is here

 String query = "SELECT uid, name, pic_square,birthday FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";


        Bundle bundal = new Bundle();
        bundal.putString("method", "fql.query");
        bundal.putString("query", query);


        mAsyncRunner.request(bundal, new AsyncFacebookRunner.RequestListener() {
            @Override
            public void onComplete(final String response, Object state) {

                Log.d("----------response----------", response + "------------------");
                String error = null;


                try {


                    JSONObject json = Util.parseJson(response);


                    final JSONArray friends = json.getJSONArray("data");


                    MainActivity.this.runOnUiThread(new Runnable() {
                        public void run() {
                            for (int i = 0; i < friends.length(); i++) {


                                JSONObject friend = null;


                                try {
                                    friend = friends.getJSONObject(i);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                                try {
                                    Log.d("--------------------------uid----------------------------------", friend.getString("id"));
                                    Log.d("-----------------------name-------------------------------", friend.getString("name"));

                                    Log.d("----------------------bithday-----------------------", friend.getString("birthday"));
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }


                            }


                        }
                    });

                } catch (JSONException e) {
                    error = "JSON Error in response" + e.getMessage();
                    Log.i("----------------111-----------------", "-----------------------------" + error + "--------------");
                }
            }

log cat error

SON Error in responseValue [{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-prn2\/t5.0-1\/1115737_1573711670_1739728801_q.jpg","uid":"1573711670","birthday":null,"name":"Pranav Lathigara"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-prn2\/t5.0-1\/1119290_1798599857_1257998989_q.jpg","uid":"1798599857","birthday":null,"name":"Rughani Hem"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-frc1\/t1.0-1\/c0.0.50.50\/p50x50\/10011434_756581737695151_651268324_t.jpg","uid":"100000299959675","birthday":"February 5, 1995","name":"Chirag Shah"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-ash1\/t5.0-1\/187115_100000367528815_1174531905_q.jpg","uid":"100000367528815","birthday":"May 14, 1992","name":"Tejas Parmar"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-frc1\/t1.0-1\/c8.0.50.50\/p50x50\/1920197_703555919667292_1918226357_s.jpg","uid":"100000386709443","birthday":"December 1","name":"Héárt Štólěr Bhärgäv Pätël"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-frc3\/t1.0-1\/p50x50\/1486641_713213512035473_346839419_t.jpg","uid":"100000404921797","birthday":"November 26, 1994","name":"Akshay Patel"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-frc3\/t1.0-1\/p50x50\/10264958_733647726665606_980187173100937418_t.jpg","uid":"100000611554280","birthday":"June 7","name":"SïRïsh ŘOý"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-prn1\/t1.0-1\/c0.0.50.50\/p50x50\/1959799_738296532871010_1759345369_t.jpg","uid":"100000720113140","birthday":"January 25","name":"Dev Bambhaniya"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-frc1\/t1.0-1\/p50x50\/10259913_763201693714824_8429936164836900161_t.jpg","uid":"100000750010202","birthday":"April 10","name":"Joy Patel"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-ash2\/t5.0-1\/1116699_100000757936751_1041047813_q.jpg","uid":"100000757936751","birthday":"December 27","name":"Manan C. Marfatia"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-ash1\/t1.0-1\/c0.0.50.50\/p50x50\/1969112_688967494474867_1437417250_t.jpg","uid":"100000848675902","birthday":null,"name":"Mohit Meena"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-ash2\/t5.0-1\/371948_100000873127987_1683047870259963920_q.jpg","uid":"100000873127987","birthday":"December 21, 1993","name":"Digvijay Dodiya"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-prn1\/t1.0-1\/c13.0.50.50\/p50x50\/10177996_673576026016865_3782712891765213211_s.jpg","uid":"100000934214075","birthday":"December 21, 1993","name":"Dishant Tolani"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-prn2\/t5.0-1\/195687_100000969796032_1290938178_q.jpg","uid":"100000969796032","birthday":"March 18","name":"Jaldeep Patel"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-ash2\/t1.0-1\/p50x50\/1505154_700729213303133_6547587592203846770_t.jpg","uid":"100000981816360","birthday":"February 11, 1998","name":"HaRsh BhalOdi"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-prn1\/t1.0-1\/c8.0.50.50\/p50x50\/1911849_767139629997536_714397599_s.jpg","uid":"100001045177534","birthday":"July 14, 1990","name":"Dilip Kamani"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-ash3\/t5.0-1\/195249_100001076415799_2050044522_q.jpg","uid":"100001076415799","birthday":"May 28","name":"Mayur Dari"},{"pic_square":"https:\/\/scontent-b.xx.fbcdn.net\/hprofile-frc3\/l\/t1.0-1\/p50x50\/10251886_718739858176046_4665185839231908159_t.jpg","uid":"100001201155668","birthday":"April 1, 1989","name":"Satish Gamara"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-prn1\/t1.0-1\/p50x50\/62433_514874881896320_84991514_t.jpg","uid":"100001214385657","birthday":"January 30, 1993","name":"Ankit Chavda"},{"pic_square":"https:\/\/fbcdn-profile-a.akamaihd.net
Was it helpful?

Solution

What you have is a JSONArray

[   // represnts json array node
    {   // represents json object node 
        "pic_square": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/t5.0-1/1115737_1573711670_1739728801_q.jpg",
        "uid": "1573711670",
        "birthday": null,
        "name": "Pranav Lathigara"
    },

So this is wrong

JSONObject json = Util.parseJson(response);

It should be

JSONArray jr = Util.parseJson(response);
for(int i=0;i<jr.length();i++)
{
     JSONObject jb = (JSONObject)jr.get(i);
     String id = jb.getString("uid"):
     String birth = jb.getString("birthday"): 
     String name = jb.getString("name");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top