簡體   English   中英

在 android jsonarray 中無法在 jsonobject 中轉換

[英]in android jsonarray cannot be converted in jsonobject

該腳本從 phpmyadmin 獲取數據,但 android studio 導致此錯誤

org.json.Jsonarray 類型無法轉換為 jsonobject

在此處輸入圖片說明

我的代碼安卓

代碼

實際上,您是從服務器獲取JSONArray而不是JSONObject 因此,您必須先解析數組,然后才能從中獲取對象。

JSONArray jsonArray = new JSONArray(response);

for(int i = 0; i < jsonArray.length(); i++) {
     JSONObject jsonObject = jsonArray.getJSONObject(i);

     String id = jsonObject.getString("id"); 
     String m_e = jsonObject.getString("M_E"); 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM