我打电话给一个Web服务,并接收这个JSON,但实例化JSONObject类抛出错误,因为你可以看到它包含波斯字符(UTF-8),我不认为这可能是原因这个问题,Json解析在Android 2
JSON:
{"teriffs": [
{"name":"برنز","id":"1000","prices":"3;400000-12;600000"},
{"name":"برنز","id":"1000","prices":"3;400000-12;600000"},
{"name":"نقره ای","id":"1002","prices":"3;700000-12;1000000"},
{"name":"نقره ای","id":"1002","prices":"3;700000-12;1000000"}]
}
错误:
org.json.JSONException: Value {"teriffs": [{"name":"برنز","id":"1000","prices":"3;400000-12;600000"},{"name":"برنز","id":"1000","prices":"3;400000-12;600000"},{"name":"نقره ای","id":"1002","prices":"3;700000-12;1000000"},{"name":"نقره ای","id":"1002","prices":"3;700000-12;1000000"}]} of type java.lang.String cannot be converted to JSONObject
CODE:
try {
JSONStringer requestMsg = new JSONStringer().object().key("Ticket").value(TempUtil.UID).endObject();
char[] c = CallServiceHelper.getCallService(requestMsg, "/WWWServices.svc/GetTeriffs");
if(c!=null){
JSONObject array = new JSONObject(new String(c));
System.out.println(array.toString());
return array;
} else {
return new JSONObject();
}
} catch (Exception e) {
e.printStackTrace();
}
块
你可以分享你的JSON代码,以便我们可以帮助你在隔离的问题? :) –
什么是String json的值? –
@SunilMishra。它包含从Web服务加载的JSON。确保它不是空字符串。它包含上面提到的JSON。 – Areff