本地解析Json
1、把j資源放在res/raw下
2、把需要解析的所有字符取出來,對象為jsonObect
?
//將json文件讀取到buffer數組中InputStream is = this.getResources().openRawResource(R.raw.getcart);byte[] buffer = new byte[is.available()];is.read(buffer); // 將字符數組轉換為UTF-8編碼的字符串String json = new String(buffer, "UTF-8");JSONObject jsonObject = new JSONObject(json);
3、如果是{}:用JSONObject,如果是[]:則用JSONArray取出來(重點,理解就很簡單了)
?
?
JSONObject objectInfo = jsonObject.getJSONObject("info");?
JSONArray arraygroup = objectInfo.getJSONArray("group");
4、取到根時,則:
?
?
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
版權聲明:本文為博主原創文章,未經博主允許不得轉載。
?
轉載于:https://www.cnblogs.com/shuyongzai/p/4703727.html
總結
- 上一篇: .Net学习笔记----2015-06-
- 下一篇: web(七)---fastcgi再进阶(