2012-02-04 244 views
0

,當我剛剛學會Android JSON Parsing Tutorial錯誤解析JSON

我下載的源代碼,併成功地與默認的JSON數據從here

運行它,然後我試圖複製他的JSON data爲localhost和我的網站

我改變了這種代碼

> private static String url = "http://api.androidhive.info/contacts/"; 

> private static String url = "http://yumugee.com/data.json"; 

> 02-04 19:38:48.343: E/JSON Parser(1233): Error parsing data 
> org.json.JSONException: Value <!DOCTYPE of type java.lang.String 
> cannot be converted to JSONObject 

我又改成了

> private static String url = "http://192.168.1.100/data.json/"; 

,我得到了一個錯誤太

> 02-04 19:30:10.332: E/JSON Parser(1201): Error parsing data 
> org.json.JSONException: Value <?xml of type java.lang.String cannot be 
> converted to JSONObject 

有誰知道我從日誌貓錯誤如何解決這個問題?

sry爲我的英語不好,希望你明白我的要求。 THX

{ 
"contacts": [ 
    { 
      "id": "c200", 
      "name": "Ravi Tamada", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "male", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    }, 
    { 
      "id": "c201", 
      "name": "Johnny Depp", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "male", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    }, 
    { 
      "id": "c202", 
      "name": "Leonardo Dicaprio", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "male", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    }, 
    { 
      "id": "c203", 
      "name": "John Wayne", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "male", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    }, 
    { 
      "id": "c204", 
      "name": "Angelina Jolie", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "female", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    }, 
    { 
      "id": "c205", 
      "name": "Dido", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "female", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    }, 
    { 
      "id": "c206", 
      "name": "Adele", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "female", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    }, 
    { 
      "id": "c207", 
      "name": "Hugh Jackman", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "male", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    }, 
    { 
      "id": "c208", 
      "name": "Will Smith", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "male", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    }, 
    { 
      "id": "c209", 
      "name": "Clint Eastwood", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "male", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    }, 
    { 
      "id": "c2010", 
      "name": "Barack Obama", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "male", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    }, 
    { 
      "id": "c2011", 
      "name": "Kate Winslet", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "female", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    }, 
    { 
      "id": "c2012", 
      "name": "Eminem", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "male", 
      "phone": { 
       "mobile": "+91 0000000000", 
       "home": "00 000000", 
       "office": "00 000000" 
      } 
    } 
] 

}

+0

看來你沒有得到任何迴應。從瀏覽器訪問網址,看到你得到任何答覆或不。 – kosa 2012-02-04 14:38:18

+0

看到我的回答下面它的工作罰款在java沒有prblm .... – 2012-02-04 15:01:51

回答

-1

此錯誤消息似乎像結果數據不是JSON格式。它只是xml字符串。

你能在這裏顯示你的結果數據嗎?

+0

沒有它的json數據...看到我的答案.... – 2012-02-04 15:03:13

+0

程序成功運行與默認源http://api.androidhive.info/聯繫人/ 但是,當我試圖用我的文件 (從http://api.androidhive.info/contacts/複製) 我之前得到一個錯誤 – yumugee 2012-02-04 15:04:41

+0

對不起,我cannt訪問該地址。 – shenhengbin 2012-02-04 15:04:42

1

如果你想從本地主機運行該代碼,你應該編寫localhost地址,如下面的http:// 10.0.2.2 /android_api/data.php,其中android_api是你的wamp www文件夾內的文件夾。而不是yoursite.in寫入10.0.2.2或您的機器的IP地址。嘗試這個。