android - 在android中递归读取json对象递归?

标签 android json parsing

我正在尝试解析以下 json (org.simple.json)

  {
   "TotalCount":4,
   "Items":[
      {
         "ProductID":879605004504,
         "Product":{
            "Subtitle":"Vibram Fivefingers",
            "ID":879605004504,
            "Attributes":[
               {
                  "Value":"Vibram Fivefingers",
                  "Key":"Brand"
               },
               {
                  "Value":"Brown",
                  "Key":"Color"
               }
            ],
            "Media":{
               "ImageTile":"http:\/\/xxxx\/v5\/products\/879605004504\/images\/tile",

            },
            "Title":"Mens Vibram FiveFingers KSO Trek Shoes",
            "References":[
               {
                  "Name":"travelcountry.com",
                  "Link":"http:\/\/www.travelcountry.com\/shop\/vibram-fivefingers\/kso-trek-mens.html?RefId=29&RefType=Affiliate"
               },
               {
                  "Name":"summithut.com",
                  "Link":"http:\/\/www.summithut.com\/products\/mens-kso-trek\/?rc=googlebase"
               }
            ]
         },
         "ID":4,
         "CreatedAt":1346523371000000
      },
      {
         "ProductID":773040867635,
         "Product":{
            "Subtitle":"Chaco",
            "ID":773040867635,
            "Attributes":[
               {
                  "Value":"Available in Multiple Colors! - CAO1405: Credence Tall Boot by Chaco Features: -Women s Credence Tall Boot in Sienna. -Available in whole and half size. -Available in Medium width only. -The upper is constructed from full grain leather. -Part of the...",
                  "Key":"Description"
               },
               {
                  "Value":"Chaco",
                  "Key":"Manufacturer"
               },
               {
                  "Value":"Adult",
                  "Key":"Age Segment"
               },
               {
                  "Value":"Black",
                  "Key":"Color"
               },
               {
                  "Value":"Boots",
                  "Key":"Footwear Type"
               },
               {
                  "Value":"5",
                  "Key":"Size"
               }
            ],
            "Media":{
               "ImageTile":"http:\/\xxxx\/v5\/products\/773040867635\/images\/tile",

            },
            "Categories":[
               "Hidden > Shoes > Women's > Boots"
            ],
            "Title":"Chaco Credence Tall Boot - Women's"
         },
         "ID":3,
         "CreatedAt":1346523325000000
      }
   ]
}

我不知道如何解析这个 json ?它有项目的总数。 谢谢。

最佳答案

这应该让你开始,你需要继续你的定义....

JSONObject rootObject = new JSONObject(inputString);
int totalCount = rootObject.getInt("TotalCount");
JSONArray items = rootObject.getJSONArray("Items");

JSONObject item = null;
JSONObject itemDetails = null;
int productID = 0;
String subtitle = null;

for(int i = 0; i < items.size(); i++) {
    item = items.getJSONObject(i);
    productId = item.getInt()"ProductId");
    itemDetails = item.getJSONObject("Product");
    subtitle = itemDetails.getString("Subtitle");
}

关于android - 在android中递归读取json对象递归?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12309375/

相关文章:

algorithm - 歧义语法(BNF 符号)

C++ 使用类标记数学表达式

android - Android中SplashScreen后台运行代码的方法

安卓 notifyDataSetChanged

Android 如何将相机图像保存在数据库中并在 ListView 中显示另一个 Activity ?

c# - Newtonsoft 在基类的序列化中包含子属性?

javascript - D3 不在折线图上绘制数据

java - Android 应用程序从网站解析 JSON

android - 在运行时从 scada 系统获取关于 android 应用程序的信息

php - PHP解析/语法错误;以及如何解决它们