Android - java.lang.RuntimeException:将String解析为JSONObject时发生Stub异常

时间:2014-02-25 12:08:50

标签: java android json android-json

当我尝试将java.lang.RuntimeException: Stub!解析为String时,我收到org.json.JSONObject异常。我的 Android API版本 19

这是我要解析的String

{
    "url": "http://www.google.com",
    "cookie": "012121",
    "filename": "Google"
}


JSONObject jsonObject = new JSONObject(str); // getting exception at this line
String url = jsonObject.getString("url");

1 个答案:

答案 0 :(得分:9)

这可能是因为你使用的是android提供的json实现,而你没有在Android设备或模拟器上运行它。

根据您的实际需要,您可以:

  • 在设备或模拟器上运行
  • 使用另一个json库而不是android
  • 中嵌入的json库
  • 在没有模拟器的情况下使用roboelectric运行测试(如果是测试):http://robolectric.org/