2016-04-14 70 views
0

我是新來的PHP,我開發的Android到PHP的Web服務,這是在本地主機工作正常。我要讓我的應用程序生活,所以我上傳了我的PHP文件在瀏覽器byethost17.com,它工作正常,返回JSON但是當我運行我的應用程序的顯示字符串不能轉換爲JSON

org.json.JSONException: Value script of type java.lang.String cannot be converted to JSONObject` 

的代碼工作正常使用JSON從本地主機解析時,問題來自免費託管網站。什麼是解決方案?有沒有好的免費網站託管網站? 100%免費?

org.json.JSONException: Value <html><body><script of type 
    java.lang.String cannot be converted to JSONObject 
at org.json.JSON.typeMismatch(JSON.java:111) 
at org.json.JSONObject.<init>(JSONObject.java:160) 
    at org.json.JSONObject.<init>(JSONObject.java:173) 






     this is result from browser when hit same url 

    {"data":[{"Category": 
{"Category_ID":"3","Category_name":"Camera","Category_image": 
"upload\/images\/7089-2015-07-09.png"}},{"Category": 
{"Category_ID":"9","Category_name":"Cars", 
"Category_image":"upload\/images\/7789-2015-07-09.png"}},{"Category": 
{"Category_ID":"4","Category_name":"Clothes", 
"Category_image":"upload\/images\/9350-2015-07-09.png"}},{"Category": 
{"Category_ID":"1","Category_name":"Computer", 
    "Category_image":"upload\/images\/1843-2015-07-09.png"}},{"Category": 
{"Category_ID":"7","Category_name":"Music", 
"Category_image":"upload\/images\/8666-2015-07-09.png"}},{"Category": 
{"Category_ID":"5","Category_name":"Other", 
"Category_image":"upload\/images\/6260-2015-07-09.png"}},{"Category": 
{"Category_ID":"2","Category_name":"Smartphone", 

"Category_image":"upload\/images\/3025-2015-07-09.png"}},{"Category": 
{"Category_ID":"8","Category_name":"Sports", 

    "Category_image":"upload\/images\/5354-2015-07-09.png"}}, 

{"Category":{"Category_ID":"10","Category_name":"waqas 
Company","Category_image":"upload\/images\/9853-2016-04-11.jpg"}}]} 
+0

W帽子字符串,你想轉換爲JSON? –

+0

其在線商店的產品數據,我發現這個qurstion類似於我的問題http://stackoverflow.com/questions/33439515/problems-in-parse-com-php-hosting –

+0

任何人都可以告訴我免費託管網站誰給我正確的JSON ???????? –

回答

0

JSON字符串你是顯示一個JSON數組不是一個JSON對象開始,嘗試將其解析到一個數組,而不是

0

你需要獲取頁面,而不是源文本。

因爲在源代碼中,免費的主機把他們的廣告聯盟。

所以,如果你得到

{"data": "stuff"} 

在頁面主體的來源是這樣的:

<html><head> 
    <script> 
     /** affliate code **/ 
    </script> 
    </head> 
    <body> 
     <span>{"data": "stuff"}</span> 
    </body> 
</html> 

我希望你明白......

(也檢查在解析爲JSON之前返回頁面源的值)