【问题标题】:Error parsing json in my Android app在我的 Android 应用程序中解析 json 时出错
【发布时间】:2013-05-27 10:47:27
【问题描述】:

在我的 Android 应用程序上从服务器解析 JSON 数据时,我收到以下错误:

org.json.json exception value <html><head><title>Apache of type java.lang.String cannot conveted to JSONObject

有人知道问题的原因吗?

【问题讨论】:

  • 检查您收到的回复。 “ Apache”不是 json。

标签: java json android-listview


【解决方案1】:

您得到的错误是JSONException。根据 json.org 的 JSON in Java(因为 Javadoc 没有那么有用):

检测到语法或程序错误时抛出 JSONException。

您尝试解析的数据不属于JSON format。它看起来像它的HTML。这可能是由于您查询了一个无效的 url,它以 HTML 格式返回了错误页面,而不是您期望的 JSON。

JSON 对象如下所示:

{
    "foobar": "some value here",
    "bla": "maybe another thing here",
    "sub-document": {
        "whatever": "lorem ipsum"
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    相关资源
    最近更新 更多