Android解析json文件
String str
中包含的 Json 字符串:
{conf:{"quantity_uom":"l",price_uom:"euro",distance_uom:"km",consumption_uom:"km/l"}}
代码:
try{
if (str!=""){
this.json = new JSONObject(str);
this.quantityUom=this.json.getString("quantity_uom");
this.distanceUom=this.json.getString("distance_uom");
this.priceUom=this.json.getString("price_uom");
this.consumptionUom=this.json.getString("consumption_uom");
}
}catch (Exception e) {
throw e;
}
我已返回 No value for amount_uom
。我怎么做错了?字符串包含 json 文本。
太感谢了。
Json string contained in String str
:
{conf:{"quantity_uom":"l",price_uom:"euro",distance_uom:"km",consumption_uom:"km/l"}}
Code:
try{
if (str!=""){
this.json = new JSONObject(str);
this.quantityUom=this.json.getString("quantity_uom");
this.distanceUom=this.json.getString("distance_uom");
this.priceUom=this.json.getString("price_uom");
this.consumptionUom=this.json.getString("consumption_uom");
}
}catch (Exception e) {
throw e;
}
I have returned No value for quantity_uom
. How I am doing wrong? String contain the json text.
Thank you so much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您首先必须从字符串中获取名为“conf”的 json 对象,然后从该 json 对象中获取其他值。
You first have to get json object named 'conf' from string and from that json object get other values.
JSON 字符串不正确。
试试这个:
The JSON string is not correct.
Try this: