show-field parsing

62 visningar
Hoppa till det första olästa meddelandet

David McCain

oläst,
21 dec. 2016 17:09:082016-12-21
till 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

oläst,
22 dec. 2016 05:49:102016-12-22
till 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!
Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden