本地解析Json
1、把j資源放在res/raw下
2、把需要解析的所有字符取出來(lái),對(duì)象為jsonObect
?
//將json文件讀取到buffer數(shù)組中InputStream is = this.getResources().openRawResource(R.raw.getcart);byte[] buffer = new byte[is.available()];is.read(buffer); // 將字符數(shù)組轉(zhuǎn)換為UTF-8編碼的字符串String json = new String(buffer, "UTF-8");JSONObject jsonObject = new JSONObject(json);
3、如果是{}:用JSONObject,如果是[]:則用JSONArray取出來(lái)(重點(diǎn),理解就很簡(jiǎn)單了)
?
?
JSONObject objectInfo = jsonObject.getJSONObject("info");?
JSONArray arraygroup = objectInfo.getJSONArray("group");
4、取到根時(shí),則:
?
?
int stock_id = jtem.getInt("stock_id");String goods_name = jtem.getString("goods_name");int qty = jtem.getInt("qty");boolean is_choose = jtem.getBoolean("is_choose");int price = jtem.getInt("price");String goods_img = jtem.getString("goods_img");String extend = jtem.getString("extend");int stock_num = jtem.getInt("stock_num");int goodsTotalPrice = jtem.getInt("goodsTotalPrice");double rate = jtem.getDouble("rate");
最后附上源碼給大家看看
http://download.csdn.net/detail/azhansy/8956277
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。
?
轉(zhuǎn)載于:https://www.cnblogs.com/shuyongzai/p/4703727.html
總結(jié)
- 上一篇: .Net学习笔记----2015-06-
- 下一篇: web(七)---fastcgi再进阶(