2012-10-08 149 views
0

我的代碼發佈在服務器中的數據, 這是我的代碼值<java.lang.String類型的DIV不能被轉換爲JSONObject的

List<NameValuePair> params = new ArrayList<NameValuePair>(); 
        params.add(new BasicNameValuePair("phone", mPhoneNumber)); 
        params.add(new BasicNameValuePair("prod_title", nama)); 
        params.add(new BasicNameValuePair("prod_desc", des)); 

        JSONObject json = jsonParser.makeHttpRequest(Constants.url_create_product, "POST", params); 


        // check log cat from response 
        Log.d("Create Response", json.toString()); 
        try { 
         int success = json.getInt(Constants.TAG_SUCCESS); 

         if (success == 1) { 
          // successfully created user 

          Intent i = new Intent(getApplicationContext(), shoop3Activity.class); 
          i.putExtra("phone", mPhoneNumber);      
          startActivity(i); 
           // closing this screen 
          finish(); 
         } else { 
          // failed to create user 
          Toast.makeText(getApplicationContext(),"Gagal bikin user", Toast.LENGTH_LONG).show(); 
         } 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        }  
        return null; 
       }   

,但它顯示的錯誤這樣

10-08 12:36:11.857: INFO/ActivityManager(59): Displayed activity shoop3.android.edu/.Activity3: 1074 ms (total 1074 ms) 
10-08 12:36:16.037: ERROR/JSON Parser(881): Error parsing data org.json.JSONException: Value <div of type java.lang.String cannot be converted to JSONObject 
10-08 12:36:16.037: DEBUG/Create Response(881): {"status":1} 
10-08 12:36:16.127: INFO/ActivityManager(59): Starting activity: Intent { cmp=shoop3.android.edu/.setupstoreActivity (has extras) } 
10-08 12:36:17.507: INFO/ActivityManager(59): Displayed activity shoop3.android.edu/.setupstoreActivity: 1191 ms (total 1191 ms) 

任何解決方案,please???它顯示錯誤解析數據...字符串不能轉換爲JSonObject

回答

2

服務器響應HTML數據,你試圖解析它爲JSON數據。這不起作用。您應該檢查傳遞給服務器的參數究竟是什麼,並在瀏覽器中對其進行測試。也許你需要登錄/認證,但你沒有通過cookie或什麼?

+0

是的,它發生在我身上,我將錯誤的值傳遞給我的一個參數。我幾乎沒有想到這一點。 –

0

發生這種情況是因爲您可能錯過了任何JSon標記或將JSonArray作爲JSonObject提及,反之亦然。 再次仔細檢查,讓我知道問題是否仍然存在

+0

它解決了,我必須使用代碼多部分形式的數據到JSON,但感謝所有,你真的幫我:)) –

+0

歡迎 高興地幫助你:) – Syn3sthete

相關問題