json解析转

一.先看看json的格式


 {
"weibo":[  //位置1 
    {
        "weibo_id": "1134",
        "uid": "150",
        "content": "#@[funk]cece请输入昵称#//@西西:乖乖",
        "ctime": "2013-02-05 16:34",
        "from": "2",
        "comment": "0",
        "transpond_id": "1119",
        "transpond": "0",
        "type": "1",
        "type_data": null,
        "from_data": false,
        "isdel": "0",
        "favorited": 0,
        "uname": "西西",
        "face": "http://www.nicemodel.net/data/uploads/avatar/150/middle.jpg",
        "transpond_data": {//位置2
            "weibo_id": "1119",
            "uid": "150",
            "content": "[cake]hhhhjjkl fghhjkkkdffh我的我是啊?那",
            "ctime": "2013-01-30 13:40",
            "from": "2",
            "comment": "2",
            "transpond_id": "0",
            "transpond": "2",
            "type": "1",
            "type_data": {
                  "thumburl": "http://www.nicemodel.net/data/uploads/2013/0130/13/small_5108b23a99660.jpg",//位置3
                  "thumbmiddleurl": "http://www.nicemodel.net/data/uploads/2013/0130/13/middle_5108b23a99660.jpg",
                  "picurl": "http://www.nicemodel.net/data/uploads/2013/0130/13/5108b23a99660.jpg",
                  "attach_id": 4279
              },
            "from_data": false,
            "isdel": "0",
            "uname": "西西",
            "face": "http://www.nicemodel.net/data/uploads/avatar/150/middle.jpg",
            "transpond_data": "",
            "timestamp": "1359524410",
            "friendtime": "01月30日 13:40",
            "favorited": 0
        },
        "timestamp": "1360053293",//位置4
        "friendtime": "02月05日 16:34"
    },
  ......
  ]
}

 二、现在我们开始一点一点的去解析它

首先最外面的一层大括号{ ..... },这个应该使用JSONObject()去获取对象


1.通过数据交互获取String json数据 jsonStr;
2,将jsonStr转化为jsonObject对象
JSONObject jsonObject = new JSONObject(json); 

3.接下来要一个getJSONArray()方法去获取,因为他是一个数组,[ ]之间的每一个{ ..... }代表数组的一个元素
4.JSONArray jsonArr = jsonObject.getJSONArray("weibo");


 

获取位置2的数据就得需要:

获取数组中的第一组对象
  5.JSONObject jsonArrObj = jsonArr.getJSONObject(0);  // 这里的0代表的就是第一个{},以此类推
  6.String transpondData = jsonArrObj.getString("transpond_data");
  7.JSONObject transpondDataObj = new JSONObject (transpondData);
 

获取位置3的数据就得需要:

 8.String typedataStr = transpondDataObj.getString("type_data");
 9.JSONObject typeDataObj = new JSONObject (typedataStr);
 10.String thumburl = typeDataObj.getString("thumburl");
 

 获取位置3的数据就得需要:

String timestampStr = jsonArrObj.getString("timestamp");
基本的json解析就分析完了

 

转载于:https://www.cnblogs.com/double0zhou/archive/2013/06/04/3116480.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值