我想要獲取來自API服務的所有數據,但我在訪問JSON響應中的不同「級別」時遇到問題。Android:在JSON響應中訪問級別
我相信我的主要問題是當內部級別包括[]
我在這裏展示的JSON響應(整個反應是巨大的)的減少部分。但是,這部分代表清楚我的問題
{
「CustomerList」:{
「CustomerType」:」residential」,
「maxAllowed」:」256」,
"serverdate":"2017-05-02",
「Purchases」:[
{
「Car」:[
{
「customerName」:」Fredrik」,
「price」:」25890」,
「currency」:」EUR」,
「Item」:{
「code」:」Audi」,
「model」:」A3」,
「engine」:」diesel」,
「data」:」2017-03-12」,
"$":"\n"
},
"Destination":{
「country」:」Germany」,
「arrivalDate」:」March 25」,
"id":"02201403",
我已經能夠訪問CustomerList
和Purchases
這樣
JSONObject customer = (JSONObject) response.get("CustomerList");
JSONArray purchases = customer.getJSONArray("Purchases");
但是訪問內部領域,如Car
,Item
或Destination
和它們的元素,現在我正在煩惱。
下面給我JSONException
for (int i = 0;i< purchases.length();i++){
JSONObject car = purchases.getJSONObject(i);
String custName = car.getString("customerName");
可能的重複[如何解析Java中的JSON](http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java ) –