Gson fromJson parsing nested json Gson fromJson parsing nested json json json

Gson fromJson parsing nested json


Problem is in inputLine.
This code works well

String str = "{ \"status_code\": 200, \"status_text\": \"Success\", \"count\": 96, \"data\": [ { \"model\": \"Spark\",\"fuel_type\": \"\", \"price\": \"352109\", \"state\": \"\", \"city\": \"Agartala\", \"crawl_date\": \"2013-10-02 05:00:02\", \"make\": \"Chevrolet\", \"variant\": \"New Spark 1.0 BS4 OBDII\" }, { \"model\": \"Spark\", \"fuel_type\": \"\", \"price\": \"378914\", \"state\": \"\", \"city\": \"Agartala\", \"crawl_date\": \"2013-10-02 05:00:03\", \"make\": \"Chevrolet\", \"variant\": \"New Spark 1.0 LS BS4 OBDII\" } ] }";CarPriceResult cpr = new Gson().fromJson(str, CarPriceResult.class);List<CarData> cd = cpr.getCarData();  

EDIT:
Also, your json does not correspond to class mapping
Json:

"data": [  

class CarPriceResult

private List<CarData> CarData;  

You should rename field to data or change key in json to CarData.
e.g.
Json:

"data": [  

class CarPriceResult

private List<CarData> data;