我有這個以.json類型GSON解析凍結
{"paging":{"page":1,"total":2015,"page_size":20,"pages":101},
"loans":[
{
"id":519729,
"name":"Hefseba Group",
"description":{"languages":["en"]},
"status":"fundraising",
"funded_amount":3125,
"basket_amount":0,
"image":{"id":1280581,"template_id":1},
"activity":"Cafe",
"sector":"Food",
"use":"to buy more stock for her cafe, and to buy more fabrics and liquid soap.",
"location":{"country_code":"TZ",
"country":"Tanzania",
"geo":{"level":"country","pairs":"-6 35","type":"point"}},
"partner_id":87,
"posted_date":"2013-02-01T09:14:17Z",
"planned_expiration_date":"2013-03-03T09:14:17Z",
"loan_amount":4025,
"borrower_count":16
},
{
"id":520550,"name":"Waridi Pendo Group",
"description":{"languages":["en"]},
"status":"fundraising",
"funded_amount":800,
"basket_amount":0,
"image":{"id":1282077,"template_id":1},
"activity":"Music Discs & Tapes",
"sector":"Retail",
"use":"to buy music equipment and DVDs and CDs, as well as to start building his house. ",
"location":{"country_code":"TZ",
"country":"Tanzania",
"geo":{"level":"country","pairs":"-6 35","type":"point"}},
"partner_id":87,
"posted_date":"2013-02-01T09:18:11Z",
"planned_expiration_date":"2013-03-03T09:18:11Z",
"loan_amount":6100,
"borrower_count":11
}
]
}
然後,我有這樣的代碼試圖解析它。
try{
JsonReader runThrough = getJsonReader(fileName);
System.out.println("File found");
Gson myGson = new Gson();
JsonParser jsonParser = new JsonParser();
JsonArray infoArray = jsonParser.parse(runThrough).getAsJsonArray();
System.out.println("Finished Parsing");
for (JsonElement piece : infoArray){
}
} catch (Exception e){
System.out.println(e);
}
我希望每個貸款最終被保存到kLoan的ArrayList,但我只是有一個空循環現在。錯誤我得到這一行凍結:
JsonArray infoArray = jsonParser.parse(runThrough).getAsJsonArray();
有在'loans'列表的末尾逗號。 – santiagobasulto
@santiagobasulto - 如果不是所有的JSON解析器都忽略了多餘的逗號,大多數情況下都是如此。 – rmlan
我認爲在planned_expiration_date之後缺少的逗號可能是真正的問題。 – schlingel