嗨,我正在尝试解析 json 字符串,但得到 jsonexception: no value found for product,我将产品作为 jsonobject 下面是我的 json 代码
{
"Product": {
"Budget": {
"Value": {
"Cake": 200,
"butter": 757993,
"Gelsd": 404130,
"Yeast": 404130,
"Yeas": 43379276,
"Gels": 1777776,
},
"Vol": {
"Cake": 27899,
"butter": 1266,
"Gelsd": 2032,
"Yeast":404130,
"Yeas": 985721,
"Gels": 16563,
}}}}
我正在做如下:
try {
JSONObject mainObject = new JSONObject(text);
JSONObject productObject = mainObject.getJSONObject("product");
JSONObject attributeObject = productObject.getJSONObject(ATTRIBUTES1);
JSONObject valueObject = attributeObject.getJSONObject(PRODUCT_VALUE);
JSONObject volumeObject = attributeObject.getJSONObject(PRODUCT_VOLUME);
String cake = valueObject.getString(PRODUCT_CAKE);
String butter = valueObject.getString(PRODUCT_BUTTER);
String gelsd = valueObject.getString(PRODUCT_GELSD);
String yeast = valueObject.getString(PRODUCT_YEAST);
String yeas = valueObject.getString(PRODUCT_YEAS);
System.out.println("cake============="+cake);
System.out.println("butter============="+butter);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我解析正确吗?