android 嵌套json数据,在Android中解析嵌套的JSON对象

我正在尝试解析一个

JSON对象,其中一部分看起来像这样:

{

"offer":{

"category":"Salon",

"description":"Use this offer now to enjoy this great Salon at a 20% discount. ",

"discount":"20",

"expiration":"2011-04-08T02:30:00Z",

"published":"2011-04-07T12:00:33Z",

"rescinded_at":null,

"title":"20% off at Jun Hair Salon",

"valid_from":"2011-04-07T12:00:31Z",

"valid_to":"2011-04-08T02:00:00Z",

"id":"JUN_HAIR_1302177631",

"business":{

"name":"Jun Hair Salon",

"phone":"2126192989",

"address":{

"address_1":"12 Mott St",

"address_2":null,

"city":"New York",

"cross_streets":"Chatham Sq & Worth St",

"state":"NY",

"zip":"10013"

}

},

等等….

到目前为止,通过这样做,我能够非常简单地解析:

JSONObject jObject = new JSONObject(content);

JSONObject offerObject = jObject.getJSONObject("offer");

String attributeId = offerObject.getString("category");

System.out.println(attributeId);

String attributeValue = offerObject.getString("description");

System.out.println(attributeValue);

String titleValue = offerObject.getString("title");

System.out.println(titleValue);`

但是,当我尝试’名称’时,它将无法正常工作.

我试过了:

JSONObject businessObject = jObject.getJSONObject("business");

String nameValue = businesObject.getString("name");

System.out.println(nameValue);

当我尝试这个时,我得到“JSONObject [business] not found.”

当我尝试:

String nameValue = offerObject.getString("name");

System.out.println(nameValue);`

正如预期的那样,我得到“未找到JSONObject [name]”.

我在这做错了什么?我遗漏了一些基本的东西……

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值