Json单个数据解析和提取(一层层剥离的方法)

JSONObject obj = new JSONObject( jsonString);

obj = obj.getJSONObject( "data" );

totalPri = (double) obj.get( "total_money" );

JSONArray array = obj.getJSONArray( "items" );

Gson gson = new Gson();

//动态数据获取到,并且传入Group和child

for (int i = 0; i < array.length(); i++) {

ShoppingCartBean info = gson.fromJson( array.get( i ).toString(), ShoppingCartBean.class );

groups.add( info );//使用JsonArray来实现获取Json数据,只能用list汪里面添加数据

List products = new ArrayList<>();

for (int j = 0; j < info.getItems().size(); j++) {

products.add( info.getItems().get( j ) );

}

children.put( String.valueOf( groups.get( i ).getStore_id() ), products );

}

你可能感兴趣的:(android)