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

tal*_*a06 5 java android json android-json

我得到java.lang.RuntimeException: Stub!异常,当我尝试解析Stringorg.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");
Run Code Online (Sandbox Code Playgroud)

Pie*_*ust 9

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

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

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