show-field parsing

62 views
Skip to first unread message

David McCain

unread,
Dec 21, 2016, 5:09:08 PM12/21/16
to Guardian Open Platform API Forum
Hello, 
I'm trying to parse data and I'm using show-fields to get the byline. The object name appears to be "fields" but when I do that and try to build the app, I get an error saying there is no value for "fields". I've tried several ways, but this is the most recent. Any guidance would be appreciate!
Thanks!!

JSONObject baseJsonResponse = new JSONObject(newsJSON);
JSONObject parentObject = baseJsonResponse.getJSONObject("response");
JSONArray newsArray = parentObject.getJSONArray("results");
JSONObject currentNews;
JSONObject fields;

for (int i = 0; i < newsArray.length(); i++) {
//JSONObject currentNews = newsArray.getJSONObject(i);
currentNews = newsArray.getJSONObject(i);
fields = newsArray.getJSONObject(i).getJSONObject("fields");


<!---- Error below ---------!>
E/QueryUtils: Problem parsing the news JSON results
              org.json.JSONException: No value for fields

manlio.po...@guardian.co.uk

unread,
Dec 22, 2016, 5:49:10 AM12/22/16
to Guardian Open Platform API Forum
Hi David,

I'm not familiar with the JAVA api but it looks like the "fields" element isn't there, are you sure you're querying the API with the right parameters? :)


(note the show-fields bit).

An easy method to debug your apps while working with Json is to print the intermediate results as you get them. E.g. you could try to print out "currentNews", see what it looks like, and take it from there. Good luck!
Reply all
Reply to author
Forward
0 new messages