我有以下方法将样本String解析为JSONObject

private JSONObject test() {
    try {

        String responseData = "{\"m_tani\":[{\"tani_cd\":\"02\",\"tani_nm\":\"cs\"},{\"tani_cd\":\"03\",\"tani_nm\":\"pc\"}]}";
        Log.i("Json", responseData.toString());
        JSONObject json = new JSONObject(responseData);

        return json;

    } catch (Exception e) {
        e.printStackTrace();
        Log.i("Json", "exception");
    }
    Log.i("Json", null);
    return null;
}

答案是:
{"m_tani":[{"tani_cd":"02","tani_nm":"cs"},{"tani_cd":"03","tani_nm":"pc"}]}

当我调试它时,从JSONObject json = new JSONObject(responseData);行跳到return null;,而不是return json;catch(Exception e)
我不知道为什么,请帮帮我

最佳答案

当一个方法有多个返回点时,这种情况会在分步调试期间发生。
当将Java字节码转换为DALVIK时,返回调用被合并(出于优化原因),当您调试代码时,可能会发现您找到了错误的代码,或者调用了多个代码。但这并没有发生,你的代码是正确的,只是在调试时它是如何出现的。
您可以查看this post以获取更多参考

07-24 09:38
查看更多