Home JSON parsing error, data not displaying
Reply: 0

JSON parsing error, data not displaying

user4596 Published in March 19, 2018, 6:22 pm

This question already has an answer here:

  • How to parse JSON in Android 4 answers

I'm just starting to learn how to use JSON in Android. I'm supposed to make an app that display news title, section and author.

I'm not really sure if the problem is in the parsing or something else but it keeps telling me there's no data.

So can I get some help with this part if it has a problem so I can fix it or go look more to where the problem is.

the JSON code:

   "response": {
        "status": "ok",
        "userTier": "developer",
        "total": 191,
        "startIndex": 1,
        "pageSize": 10,
        "currentPage": 1,
        "pages": 20,
        "orderBy": "relevance",
        "results": [{
            "id": "film/2017/may/25/12-jours-review-raymond-depardon-documentary-psychiatric-hospital-judge",
            "type": "article",
            "sectionId": "film",
            "sectionName": "Film",
            "webPublicationDate": "2017-05-25T15:37:15Z",
            "webTitle": "12 Jours review – a devastating glimpse into broken souls",
            "webUrl": "https://www.theguardian.com/film/2017/may/25/12-jours-review-raymond-depardon-documentary-psychiatric-hospital-judge",
            "apiUrl": "https://content.guardianapis.com/film/2017/may/25/12-jours-review-raymond-depardon-documentary-psychiatric-hospital-judge",
            "fields": {
                "headline": "12 Jours review – a devastating glimpse into broken souls",
                "starRating": "4",
                "shortUrl": "https://gu.com/p/6g6hn",
                "thumbnail": "https://media.guim.co.uk/1dbf594e183ebe5428fe88c82784c55908b4753c/0_0_3598_2160/500.jpg"
            "tags": [{
                "id": "profile/wendy-ide",
                "type": "contributor",
                "sectionId": "film",
                "sectionName": "Film",
                "webTitle": "Wendy Ide",
                "webUrl": "https://www.theguardian.com/profile/wendy-ide",
                "apiUrl": "https://content.guardianapis.com/profile/wendy-ide",
                "references": [],
                "firstName": "wendy",
                "lastName": "ide"
            "isHosted": false,
            "pillarId": "pillar/arts",
            "pillarName": "Arts"

all I need is the title, section, author and the url. So I wrote it like this:

 private static List<News> extractFeatureFromJson(String newsJSON) {
    if (TextUtils.isEmpty(newsJSON)) {
        return null;
    List<News> news = new ArrayList<>();
    try {

      JSONObject baseJsonResponse = new JSONObject(newsJSON);
        String response = baseJsonResponse.getString("response");
        JSONObject object = new JSONObject(response);;
        JSONArray newsArray=object.getJSONArray("results");
        for (int i = 0; i < newsArray.length(); i++) {
            JSONObject currentNews = newsArray.getJSONObject(i);
            JSONObject results = currentNews.getJSONObject("results");
            String title = results.getString("webTitle");
            String section = results.getString("sectionName");
            String author = results.getString("firstName");
            String url = results.getString("webUrl");

            News nNews = new News(title, section, author, url);


    } catch (JSONException e) {
        Log.e("QueryUtils", "Problem parsing the news JSON results", e);
    return news;

It's a new concept for me and I'm very confused, I'd really appreciate some help.


I'm using a loader in the same app, if the list is empty it would display a string that there's no data and that's what it keeps on appearing. I have no idea what's the problem.

public void onLoadFinished(Loader<List<News>> loader, List<News> news) {
    View loadingIndicator = findViewById(R.id.loading_indicator);

    if (news != null && !news.isEmpty()) {
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.43882 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO