I am able to retrieve section name, URL, web title, and headline from parsing JSON data with this code snippet. However, I seem to be encountering an issue where I cannot extract the last modified date. Here is the JSON structure:
{
"response":{
"status":"ok",
"userTier":"developer",
"total":368,
"startIndex":1,
"pageSize":10,
"currentPage":1,
"pages":37,
"orderBy":"relevance",
"results":[
{
"id":"technology/2017/may/24/fitness-trackers-out-of-step-when-measuring-calories-research-shows",
"type":"article",
"sectionId":"technology",
"sectionName":"Technology",
"webPublicationDate":"2017-05-24T15:00:24Z",
"webTitle":"Fitness trackers out of step when measuring calories, research shows",
"webUrl":"https://www.theguardian.com/technology/2017/may/24/fitness-trackers-out-of-step-when-measuring-calories-research-shows",
"apiUrl":"https://content.guardianapis.com/technology/2017/may/24/fitness-trackers-out-of-step-when-measuring-calories-research-shows",
"fields":{
"headline":"Fitness trackers out of step when measuring calories, research shows",
"lastModified":"2017-05-24T15:02:19Z",
"thumbnail":"https://media.guim.co.uk/8d3e17604195078ec89e20329e2ddc5027eca8ea/0_213_6362_3817/500.jpg"
},
"isHosted":false
},
Below is my code for parsing the JSON data:
JSONObject response = root.getJSONObject("response");
if(response.has("results")){
JSONArray results = response.getJSONArray("results");
for(int i=0;i<results.length();i++){
long lastModified=0;
String headline=null;
JSONObject details=results.getJSONObject(i);
String sectionName=details.getString("sectionName");
Log.i(LOG_TAG,sectionName);
String webUrl=details.getString("webUrl");
Log.i(LOG_TAG,webUrl);
if(details.has("fields")){
JSONObject fields=details.getJSONObject("fields");
if(fields.has("headline")){
headline =fields.getString("headline");
Log.i(LOG_TAG,headline);}
if(fields.has("lastModified")){
lastModified =fields.getLong("lastModified");
Log.i(LOG_TAG, String.valueOf(lastModified));}}
Despite implementing this code, I am unable to retrieve the last modified date. I am unsure of why this particular information is not being successfully extracted.