在我的Android应用中解析json时出错

时间:2013-05-27 10:47:28

标签: java json android-listview

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

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

有人知道造成这个问题的原因吗?

1 个答案:

答案 0 :(得分:0)

您获得的错误是JSONException。根据json.org的JSON in Java(因为Javadoc没有帮助):

  

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

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

JSON对象如下所示:

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