在此代碼中,TextView 字段在傳遞給 json 時不能有任何值,并且警告是無法將 json 對象轉換為 json 數組String json = strListingsDetails; try { JSONArray jsonArray = new JSONArray(json); JSONObject jsonObject = new JSONObject(jsonArray.getJSONObject(0).toString()); JSONArray dataListArray = jsonObject.getJSONArray("DataList"); if (dataListArray != null && dataListArray.length() != 0) { for (int i = 0; i < dataListArray.length(); i++) { JSONObject jsonObject1 = dataListArray.getJSONObject(i); String listingId = jsonObject1.getString("ListingID"); String specification = jsonObject1.getString("Specifications"); String description = jsonObject1.getString("Description"); String manufacturer = jsonObject1.getString("Manufacturer"); String brand = jsonObject1.getString("Brand"); String machineType = jsonObject1.getString("ManchineType"); String condition = jsonObject1.getString("Condition"); String yearOfMfg = jsonObject1.getString("YearofMfg"); String Price=jsonObject1.getString("Price"); String ShowPrice=jsonObject1.getString("ShowPrice"); String country = jsonObject1.getString("Country"); String state = jsonObject1.getString("State"); String city = jsonObject1.getString("City"); String qty = jsonObject1.getString("Qty"); String height = jsonObject1.getString("Height"); String width = jsonObject1.getString("Width"); String length = jsonObject1.getString("Length"); String weight = jsonObject1.getString("Weight"); String warranty = jsonObject1.getString("Warranty"); String expiredOn = jsonObject1.getString("ExpiredOn");
2 回答

婷婷同學_
TA貢獻1844條經驗 獲得超8個贊
無法將 json 對象轉換為 json 數組
您正在嘗試解析 JSON 字符串,它是 JSON 對象而不是數組
像這樣試試。
JSONObject jsonObject = new JSONObject(json);
JSONArray dataListArray = jsonObject.getJSONArray("DataList");

呼如林
TA貢獻1798條經驗 獲得超3個贊
請按照我的猜測匹配您的json:
[
{
"DataList": [
{
"ListingID": "value",
"Specifications": "value",
"Description": "value",
"Manufacturer": "value",
"Brand": "value"
...
}
]
}
]
記錄你的json,你會找到答案
添加回答
舉報
0/150
提交
取消