Reputation: 1147
I am trying to get facebook feeds of a page. When I open this link in browser, the full json appears with no problem but when I parse it using following code only the first two posts get displayed in app.
url = "https://graph.facebook.com/v2.2/awaaziitkgp/feed?access_token="
+ static_token;
for parsing, i am doing this
ServiceHandler sh = new ServiceHandler();
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
contacts = jsonObj.getJSONArray(TAG_DATA);
String x = null;
Log.d("contact.length", x.valueOf(contacts.length()));
// looping through All Contacts
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
String id = c.getString(TAG_ID);
String message = c.getString(TAG_MESSAGE);// feed
String createtime = c.getString(TAG_CREATETIME);// date,
// time
Log.d("POSTS", message); // created
The first two json objects are getting parsed correctly, but the rest are not visible.
Upvotes: 1
Views: 49
Reputation: 30
Two of your JSONObjects are getting parsed without any problem. I think the field "message" that you are searching is not available in your third object.
Check you JSON properly. Hope it helps.
Upvotes: 0
Reputation: 1147
I have found the solution. The problem was is JSON file. Some of the posts didn't contain message field, that's why on third post due to no "message" field, JSONObject returned empty and terminated the loop.
I'd added if (c.has("message") == true)
before getting data from message field to avoid null JSONObject.
Upvotes: 1