亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

如何使用 volley post 方法更新嵌套 json 對象的值?

如何使用 volley post 方法更新嵌套 json 對象的值?

絕地無雙 2023-03-31 14:56:38
我正在做一個項目,用戶將在其中輸入他的數據,我們需要使用 API 存儲數據。我必須更新嵌套的 json 對象中的值。我在排球中使用 POST 方法來更新數據。我的問題是我無法更新嵌套的 JSON 對象。我也在使用 GSON,所以我有結果、地址和聯系人的模型類。更新前{    "id": 58,    "address": null,    "contact": null}更新后  {    "id": 58,    "address": {        "id":50,        "first_line": "first_line",        "locality": null,        "state": "state",        "country": "country"    },    "contact": {       "primary_number": "primary",       "secondary_number": "secondary"    }}
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

您可以嘗試以下方式


try {

            JSONObject obj=new JSONObject();


            obj.put("id", 58);


            JSONObject contact=new JSONObject();

            contact.put("id", "smome value");

            contact.put("first_line", "smome value");

            contact.put("locality", "smome value");


            JSONObject address=new JSONObject();

            address.put("primary_number", "primary");

            address.put("secondary_number", "secondary");


            obj.put("address", address);

            obj.put("contact", contact);

        }catch (Exception e) {

            e.printStackTrace();

        }

現在輸出如下所示


   {

  "id": 58,

  "address": {

    "primary_number": "primary",

    "secondary_number": "secondary"

  },

  "contact": {

    "first_line": "smome value",

    "locality": "smome value",

    "id": "smome value"

  }

}


查看完整回答
反對 回復 2023-03-31
  • 1 回答
  • 0 關注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號