【问题标题】:How can I get inside info object using volley in android java如何在 android java 中使用 volley 获取内部信息对象
【发布时间】:2021-07-27 08:25:38
【问题描述】:

这是json数据,我想在android java中使用volley显示信息对象希望你能回答这个问题谢谢

"data": {
            "type": "customer",
            "name": "Sasmple name",
            "phone": "1234567",
            "email": "sample@gmail.com",
            "email_verified_at": null,
            "created_at": "2021-05-04T08:24:49.000000Z",
            "updated_at": "2021-05-04T08:24:49.000000Z",
            "info": {
                "id": 63,
                "user_id": 381,
                "fname": "Sample",
                "mname": null,
                "lname": "Name",
                "gender": null,
                "image": null,
                "birthdate": null,
                "address": "Sample, Sample City (capital), Sample",
                "address_code": "{\"region\":\"07\",\"province\":\"0722\",\"citymun\":\"072217\",\"barangay\":\"072217027\"}",
                "bank_number": "17171717171717171717",
                "bank_name": "Sample bank",
                "created_at": "2021-05-04T08:24:49.000000Z",
                "updated_at": "2021-05-04T08:24:49.000000Z"
            }
        }

这是我使用的代码

JSONObject json= null;
        try {
            json = new JSONObject("info");
            for(int i=0; i<json.length(); i++){
                JSONObject item = json.getJSONObject(String.valueOf(json));
                String province_id = item.getString("id");
                String province_code = item.getString("fname");
                String province_desc = item.getString("lname");
                String province_regcode = item.getString("address");
                String province_citycode = item.getString("address_code");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

【问题讨论】:

  • 您能否展示您已经完成了多少工作,以便我们从那里为您提供帮助
  • 是的先生,我编辑我的帖子先生
  • @TudeChristianNeil 请检查我的回答

标签: java android json android-volley


【解决方案1】:

请阅读更多关于 JSON 对象和 Json 数组here

回答你的问题

 try {
            JSONObject jsonData = new JSONObject(httpStringResponse);
            JSONObject infoItem = json.getJSONObject("info");           
            String province_id = infoItem.getString("id");
            String province_code = infoItem.getString("fname");
            String province_desc = infoItem.getString("lname");
            String province_regcode = infoItem.getString("address");
            String province_citycode = infoItem.getString("address_code");

        } catch (JSONException e) {
            e.printStackTrace();
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-01
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    相关资源
    最近更新 更多