如何在 android java 中使用 volley 获取内部信息对象

How can I get inside info object using volley in android java

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

"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();
        }

请详细阅读 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();
        }