Trouble parsing this json response
I'm trying to parse the following json response:
[
{
"modelTrimList":{
"modelTrim":[
{
"bodyStyle":"5-DOOR",
"cylinders":4,
"highwayMpg":0,
"modelCode":6203,
"transmission":"Manual",
"cityMpg":0,
"msrp":16000,
"description":"5-Door",
"modelYear":2011,
"name":"Scion xb",
"curbWeight":0,
"@id":"81454531",
"effectiveDate":"4\/28\/10",
"displayName":"xB",
"deliveryFee":775
},
{
"bodyStyle":"5-DOOR",
"cylinders":4,
"highwayMpg":0,
"modelCode":6202,
"transmission":"Automatic",
"cityMpg":0,
"msrp":16950,
"description":"5-DOOR",
"modelYear":2011,
"name":"Scion xb",
开发者_如何转开发 "curbWeight":0,
"@id":"81454516",
"effectiveDate":"4\/28\/10",
"displayName":"xB",
"deliveryFee":720
}
]
},
"name":"xB",
"@id":"Scion xb"
},
{
"modelTrimList":{
"modelTrim":[
{
"bodyStyle":"3 DOOR LIFTBACK",
"cylinders":4,
"highwayMpg":0,
"modelCode":6223,
"transmission":"Manual",
"cityMpg":0,
"msrp":18275,
"description":"2 DOOR L\/B",
"modelYear":2011,
"name":"Scion tC",
"curbWeight":3945,
"@id":"84604049",
"effectiveDate":"8\/6\/10",
"displayName":"tC",
"deliveryFee":720
},
{
"bodyStyle":"3 DOOR LIFTBACK",
"cylinders":4,
"highwayMpg":0,
"modelCode":6222,
"transmission":"Automatic",
"cityMpg":0,
"msrp":19275,
"description":"2 DOOR L\/B",
"modelYear":2011,
"name":"Scion tC",
"curbWeight":3945,
"@id":"84604028",
"effectiveDate":"8\/6\/10",
"displayName":"tC",
"deliveryFee":720
}
]
},
"name":"tC",
"@id":"Scion tC"
},
{
"modelTrimList":{
"modelTrim":[
{
"bodyStyle":"5-DOOR",
"cylinders":4,
"highwayMpg":0,
"modelCode":6233,
"transmission":"Manual",
"cityMpg":0,
"msrp":15045,
"description":"5-DOOR",
"modelYear":2011,
"name":"Scion xd",
"curbWeight":3605,
"@id":"91724869",
"effectiveDate":"12\/8\/10",
"displayName":"xD",
"deliveryFee":775
},
{
"bodyStyle":"5-DOOR",
"cylinders":4,
"highwayMpg":0,
"modelCode":6232,
"transmission":"Automatic",
"cityMpg":0,
"msrp":15845,
"description":"5-DOOR",
"modelYear":2011,
"name":"Scion xd",
"curbWeight":3605,
"@id":"91724562",
"effectiveDate":"12\/8\/10",
"displayName":"xD",
"deliveryFee":775
}
]
},
"name":"xD",
"@id":"Scion xd"
}
]
I can't seem to be parsing it correctly please advice and if possible a sample code that I could use, any ideas are more than welcome.
You need to wrap it with []
: right now it is not valid JSON.
EDIT: if it is properly wrapped, try this:
JSONArray js = new JSONArray(newjson);
Toast.makeText(getApplicationContext(),js.toString(), Toast.LENGTH_LONG).show();
for (int i = 0; i < js.length(); i++) {
Toast.makeText(getApplicationContext(),js.getJSONObject(i).getString("name").toString(), Toast.LENGTH_LONG)
.show();
That's because your JSON isn't valid, it looks like it should be an array of modelTrimList
s
Easiest way to answer this is to run it through an online validation tool such as JSON Lint:
http://jsonlint.com/
With your example it suggested that you have an error on line 42:
Parse error on line 42: ... "@id":"Scion xb"},{ "modelTrimLi ----------------------^ Expecting 'EOF'
精彩评论