JSON、GSON解析

今天弄微信支付时候碰到了解析数据,费了好大劲,一定要写下来

这种类型

List, String>> listOfMaps = new ArrayList, String>>();
对他进行的遍历

 
  
for (int i = 0; i < products.size(); i++) {
   Map, String> mapProduct = new HashMap, String>();
   mapProduct.put("pid", products.get(i).pid);
   mapProduct.put("puid", products.get(i).puid);
   mapProduct.put("pu_count", String.valueOf(products.get(i).pu_count));
   mapProduct.put("pu_name", products.get(i).pu_name);
   mapProduct.put("pu_description", products.get(i).pu_description);
   mapProduct.put("pu_price", products.get(i).pu_price);
   mapProduct.put("pu_point", products.get(i).pu_point);
      listOfMaps.add(mapProduct);
}

最后想要得到listOfMaps这个对象的属性
需要这样:::
 
String json = new Gson().toJson(params);
将这个json打印出来
就得到这种:
{"autoCloseInputStreams":false,"contentEncoding":"UTF-8",
"elapsedFieldInJsonStreamer":"_elapsed","fileArrayParams":{},
"fileParams":{},"forceMultipartEntity":false,"isRepeatable":false,
"streamParams":{},"urlParams":{"address":"在睡觉就喜欢还好吧哈哈哈",
"reservetime":"1479988824","sendtype":"0",
"token":"focks4i59lj7ckr4ul2d8c9bn6001479978907",
"realname":"小将信将疑家","uid":"372","password":"",
"handphone":"15638191676","district":"上海市 上海市",
"ttype":"2","comment":"","reservetype":"1"},
"urlParamsWithObjects":{"products":[{"pu_count":"1",
"pid":"116","puid":"147","pu_price":"4.0"},
{"pu_count":"1","pid":"116","puid":"147","pu_price":"4.0"}]},
"useJsonStreamer":false}

你可能感兴趣的:(Android)