我试图解析JSON对象,部分看起来是这样的:解析嵌套的JSON对象的Android
{
"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 [商家]未找到”
JSONObject businessObject = jObject.getJSONObject("business");
String nameValue = businesObject.getString("name");
System.out.println(nameValue);
当我尝试,我得到
,当我尝试:
String nameValue = offerObject.getString("name");
System.out.println(nameValue);`
我得到的,符合市场预期, “JSONObject的[名]未发现”。
我在这里做错了什么?我失去了一些基本的东西....
您好我refred以下页面,并得到了解决 http://stackoverflow.com/questions/5986123/parsing-nested-json-object-in-android – 2012-01-10 08:28:06