且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何循环并获取json对象的特定值,如何使用该json对象获取该json对象中存在的其他实体?

更新时间:2021-11-11 21:57:52

我假设您从完整的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!
}