JSON取嵌套的值

 

例如这个feeBlockList

我想取到里面的fee

首先,要知道这是一个循环结构,那么feeBlockList就是一个JSONArray(import com.alibaba.fastjson.JSONArray;)

通过

String feeBlockList = datadliveID.getString("feeBlockList");
            JSONArray feeBlockList1 =JSONArray.parseArray(feeBlockList);

就可以取到整个循环体的值

在进一步用循环取取值就好

for(int k=0;k<feeBlockList1.size();k++) {
                JSONObject temp = (JSONObject) feeBlockList1.get(k);
            //    Float preOrderFee = Float.valueOf(temp.getString("preOrderFee"));
                if(!temp.getString("type").equals("0")&!temp.getString("type").equals("1")&!temp.getString("type").equals("4001")){
                    ConsumablesCost = ConsumablesCost+ Float.valueOf(temp.getString("fee"));    
                }
            }

 


版权声明:本文为weixin_44854206原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。