创建JSONObject时,org.json未报告的异常
问题描述:
任何人都可以帮我理解出了什么问题吗?
Can anyone help me understand what is going wrong?
unreported exception org.json.JSONException; must be caught or declared to be thrown
jsonObj = new JSONObject("{\"count\":3939,\"has_more\":true,\"map_location\":{\"lat\":0.60996950000000183,\"lon\":-27.568517000000003,\"panoramio_zoom\":16},\"photos\":[{\"height\":375,}]}"); //creates the JSON object from the jsonString, for parsing
^
1错误
我正在使用org.json,我想我已经正确设置了所有内容。我正在尝试使用org.json中的构造函数创建一个JSONObject,它接受一个源字符串,并且我一直得到这个异常。我不确定我发送的字符串有什么问题。谢谢
I'm using org.json, and I think I have everything set up correctly. I'm trying to create a JSONObject using the constructor in org.json that takes a source string, and I keep getting this exception. I'm not sure what is wrong with the string that I am sending in. Thanks
答
通过创建尝试来捕获您的异常catch
Catch your Exception by creating try and catch
try {
JSONObject jsonObj = new JSONObject("{\"count\":3939,\"has_more\":true,\"map_location\":{\"lat\":0.60996950000000183,\"lon\":-27.568517000000003,\"panoramio_zoom\":16},\"photos\":[{\"height\":375,}]}");
System.out.println(jsonObj);
} catch (JSONException e) {
//some exception handler code.
}
或者是你的调用方法异常。
Or either thorws your exception to caller method.
public String yourMethod(String jsonString) throws JSONException