0
的Json包含在String str
字符串:的Android解析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 quantity_uom
。我怎么做错了?字符串包含json文本。
非常感谢。
'str!=“”'不能用于Java/Android。使用这个:'!str.equals(“”)' – WarrenFaith
你的字符串不是有效的JSON。 – JeremyP