创建JSONObject时,org.json未报告的异常 [英] org.json unreported exception while creating a JSONObject

查看:790
本文介绍了创建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  

这篇关于创建JSONObject时,org.json未报告的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆