如何循环并获取json对象的特定值,如何使用该json对象获取该json对象中存在的其他实体? [英] How to loop and get the specific value of the json object ,how can i use that json object to get the other entity present in that json object?

查看:114
本文介绍了如何循环并获取json对象的特定值,如何使用该json对象获取该json对象中存在的其他实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我正在使用Java.

  1. I am using java.

我已将以下答复粘贴以供参考.我需要循环以下JSON Array响应.

I have pasted below response for reference. I need to loop the below JSON Array response.

我可以得到完整的答复.但是,我需要先访问设备类型,例如:deviceType = android,然后使用该设备类型,我需要获取该特定设备类型的ID,例如:id = 16.

I can able to get the full response. But, I need to access the device Type first for example:deviceType=android and then using that device type I need to get the id of that particular device type for example: id=16.

Response:
{
  "BannerConfigurations": [
    {
      "id": 16,
      "partnerId": 69,
      "appId": "28470216",
      "affiliateData": "",
      "status": true,
      "deviceType": "ios",
      "daysHidden": 15,
      "daysReminder": 30
    },
    {
      "id": 161,
      "partnerId": 69,
      "appId": "com.android.news",
      "affiliateData": "",
      "status": true,
      "deviceType": "android",
      "daysHidden": 15,
      "daysReminder": 30
    }
  ]
}

推荐答案

我假设您从完整的JSONObject开始,但是如果要使用横幅配置数组,则可以跳过第一行.

I'm assuming you are starting with the full JSONObject but you can skip the first line if you've for the banner configurations array.

JSONObject data = [insert something following your structure above];
JSONArray bannerConfigurations = data.get("BannerConfigurations");
for (int i=0; i<bannerConfigurations.length(); i++) {
    JSONObject device = bannerConfigurations.getJSONObject(i);
    String deviceType = device.getString("deviceType");
    int id = device.getInt("id");
    // do stuff!
}

这篇关于如何循环并获取json对象的特定值,如何使用该json对象获取该json对象中存在的其他实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆