{"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]”.
我在这做错了什么?我遗漏了一些基本的东西……
解决方法 好吧,我是个白痴.这很有效.JsONObject businessObject = offerObject.getJsONObject("business");String nameValue = businessObject.getString("name");System.out.println(nameValue);
如果我只想在张贴前两秒钟……杰斯!
总结以上是内存溢出为你收集整理的在Android中解析嵌套的JSON对象全部内容,希望文章能够帮你解决在Android中解析嵌套的JSON对象所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)