1
[
  {
    "CatID":1,
    "CatName":"Enviro Monitor",
    "SubCatID":1,
    "SubCatName":"Air quality",
    "title":"The quality of air you breathe in Chennai is worse than in Delhi",
    "source":"Zee News, NDTV",
    "description":"The quality of air you breathe in Chennai is worse than in Delhi. Official air quality data for the first half of this year shows that while Delhi faces high levels of air pollution, Kanpur, Varanasi and Chennai are worse off. Averaging across the ten pollution monitoring stations in the city, a little over a quarter of the days from January to June this year in Delhi had an Air Quality Index value of severe (3.2 per cent), very poor (8.7 per cent) or poor (14.4 per cent). In comparison, nearly half of all days in Kanpur were of severe, very poor or poor air quality. Varanasi had no ‘severe’ days, but nearly half of all days were either of very poor or poor air quality. Averaging across its three monitoring stations, Chennai had the highest proportion of ‘severe’ days (17.7 per cent), and a third of all days were either of severe, very poor or poor air quality.\r\nSource. The Hindu, 15 July 2015 Sewage treatment Waste disposal fgfgfgfgfgfgfg eeeeee"
  }
]

This is the json response from the server.

How to parse this Json. I am using this code but it is showing json mismatch

json_array = new JSONArray(jsonStr);
for (int i = 0; i < json_array.length(); i++) {
  JSONObject c = json_array.getJSONObject(i);
  String title = c.getString(KEY_TITLE);
}

I am taking array first and then object.

Sachin Malik
  • 129
  • 9
  • 1
    This is your home work. Do by your self. We are not here for doing your Home work. – M D Feb 04 '16 at 06:49
  • Possible duplicate of [How to parse JSON in Android](http://stackoverflow.com/questions/9605913/how-to-parse-json-in-android) – Iamat8 Feb 04 '16 at 06:53
  • You need to refer some parsing example... Like.. http://stackoverflow.com/questions/18977144/how-to-parse-json-array-not-json-object-in-android – Raghav Mehta Feb 04 '16 at 06:53
  • you can see i m parsing the json correctly, still it is showing error. first i had taken an array and from that objects are retrieved. still i m getting error, and i think that is why this community is here for. – Sachin Malik Feb 04 '16 at 07:05

3 Answers3

-1
It should be



 [
      {
        "CatID":1,
        "CatName":"Enviro Monitor",
        "SubCatID":1,
        "SubCatName":"Air quality",
        "title":"The quality of air you breathe in Chennai is worse than in Delhi",
        "source":"Zee News, NDTV",
        "description":"The quality of air you breathe in Chennai is worse than in Delhi. Official air quality data for the first half of this year shows that while Delhi faces high levels of air pollution, Kanpur, Varanasi and Chennai are worse off. Averaging across the ten pollution monitoring stations in the city, a little over a quarter of the days from January to June this year in Delhi had an Air Quality Index value of severe (3.2 per cent), very poor (8.7 per cent) or poor (14.4 per cent). In comparison, nearly half of all days in Kanpur were of severe, very poor or poor air quality. Varanasi had no ‘severe’ days, but nearly half of all days were either of very poor or poor air quality. Averaging across its three monitoring stations, Chennai had the highest proportion of ‘severe’ days (17.7 per cent), and a third of all days were either of severe, very poor or poor air quality.\r\nSource. The Hindu, 15 July 2015 Sewage treatment Waste disposal fgfgfgfgfgfgfg eeeeee"
      }
    ]
Abhinaw Kumar
  • 132
  • 1
  • 5
-2

Your JSON format is wrong:

[
  {
    "CatID":1,
    "CatName":"Enviro Monitor",
    "SubCatID":1,
    "SubCatName":"Air quality",
    "title":"The quality of air you breathe in Chennai is worse than in Delhi",
    "source":"Zee News, NDTV",
    "description":"The quality of air you breathe in Chennai is worse than in Delhi. Official air quality data for the first half of this year shows that while Delhi faces high levels of air pollution, Kanpur, Varanasi and Chennai are worse off. Averaging across the ten pollution monitoring stations in the city, a little over a quarter of the days from January to June this year in Delhi had an Air Quality Index value of severe (3.2 per cent), very poor (8.7 per cent) or poor (14.4 per cent). In comparison, nearly half of all days in Kanpur were of severe, very poor or poor air quality. Varanasi had no ‘severe’ days, but nearly half of all days were either of very poor or poor air quality. Averaging across its three monitoring stations, Chennai had the highest proportion of ‘severe’ days (17.7 per cent), and a third of all days were either of severe, very poor or poor air quality.\r\nSource. The Hindu, 15 July 2015 Sewage treatment Waste disposal fgfgfgfgfgfgfg eeeeee"
  }
}

Shouldn't it be closed with a square bracket?

Jörn Buitink
  • 2,906
  • 2
  • 22
  • 33
-2

Then Try this:

[
  {
    "CatID":"1",
    "CatName":"Enviro Monitor",
    "SubCatID":"1",
    "SubCatName":"Air quality",
    "title":"The quality of air you breathe in Chennai is worse than in Delhi",
    "source":"Zee News, NDTV",
    "description":"The quality of air you breathe in Chennai is worse than in Delhi. Official air quality data for the first half of this year shows that while Delhi faces high levels of air pollution, Kanpur, Varanasi and Chennai are worse off. Averaging across the ten pollution monitoring stations in the city, a little over a quarter of the days from January to June this year in Delhi had an Air Quality Index value of severe (3.2 per cent), very poor (8.7 per cent) or poor (14.4 per cent). In comparison, nearly half of all days in Kanpur were of severe, very poor or poor air quality. Varanasi had no ‘severe’ days, but nearly half of all days were either of very poor or poor air quality. Averaging across its three monitoring stations, Chennai had the highest proportion of ‘severe’ days (17.7 per cent), and a third of all days were either of severe, very poor or poor air quality.\r\nSource. The Hindu, 15 July 2015 Sewage treatment Waste disposal fgfgfgfgfgfgfg eeeeee"
  }
]

quotes should be there, either int or string.

Abhinaw Kumar
  • 132
  • 1
  • 5