第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嘗試解析 JSON 數(shù)據(jù)時出現(xiàn)此錯誤 W/System.err: org.json.

嘗試解析 JSON 數(shù)據(jù)時出現(xiàn)此錯誤 W/System.err: org.json.

慕田峪7331174 2023-06-04 17:48:25
我正在嘗試從我的休息 api 中檢索客戶對象。我使用 spring data jpa 生成了 api。我已經(jīng)使用 volley 從 api 中檢索信息。我不知道我做錯了什么。因為我是 android 的新手,所以我不太清楚。有人可以幫我從我的 Json api 中解析客戶對象嗎?我的 api 看起來像這樣:{  "_embedded": {    "customers": [      {        "firstName": "Alexander",        "lastName": "arnold",        "email": "trentarnold@liverpool.com",        "password": "cornertakenquickly",        "_links": {          "self": {            "href": "http://localhost:8080/api/customers/1"          },          "customer": {            "href": "http://localhost:8080/api/customers/1"          }        }      },      {        "firstName": "test",        "lastName": "tester",        "email": "dulalsujan911@gmail.com",        "password": "12345678",        "_links": {          "self": {            "href": "http://localhost:8080/api/customers/2"          },          "customer": {            "href": "http://localhost:8080/api/customers/2"          }        }      }    ]  },  "_links": {    "self": {      "href": "http://localhost:8080/api/customers{?page,size,sort}",      "templated": true    },    "profile": {      "href": "http://localhost:8080/api/profile/customers"    }  },  "page": {    "size": 20,    "totalElements": 2,    "totalPages": 1,    "number": 0  }}
查看完整描述

2 回答

?
牛魔王的故事

TA貢獻(xiàn)1830條經(jīng)驗 獲得超3個贊

做這個 :


@Override

    public void onResponse(JSONObject response) {


            try {

               JSONObject json = new JSONObject(response); 

               JSONObject json_embedded = json.getJSONObject("_embedded");// need to access JSONObject("_embedded")

               JSONArray jsonArray = json_embedded.getJSONArray("customers"); // then get JSONARRAY

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

                    JSONObject customer = jsonArray.getJSONObject(i);

                    emailList.add(customer.getString("email"));

                    passwordList.add(customer.getString("password"));

                }


            } catch (Exception e) {

               e.printStackTrace();

            }

    }

注意:您的 json 數(shù)組(customers)在_embedded中,這就是它顯示異常的原因。


查看完整回答
反對 回復(fù) 2023-06-04
?
阿晨1998

TA貢獻(xiàn)2037條經(jīng)驗 獲得超6個贊

您需要先訪問_embedded對象。


try {

    JSONObject embedded = response.getJSONObject("_embedded");

    JSONArray jsonArray = embedded.getJSONArray("customers");

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

        JSONObject customer = jsonArray.getJSONObject(i);

        emailList.add(customer.getString("email"));

        passwordList.add(customer.getString("password"));

    }

} catch (Exception e) {

    e.printStackTrace();

}


查看完整回答
反對 回復(fù) 2023-06-04
  • 2 回答
  • 0 關(guān)注
  • 202 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號