7

当我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");
4

1 回答 1

11

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

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

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