2013-10-07 126 views
0

我想創建Android客戶端應用程序,它使用來自asp.net服務器應用程序的基於asmx web服務的JSON。我的服務器代碼返回JSON fromat結果。我試圖從Internet.It的示例代碼convenient.But用我自己的服務器應用程序(「http://stockcluster.com/CurrentPeriod.asmx/GetGrowthPersentage」)下面的錯誤出現,而不是JSON對象:無法轉換爲JSON對象android

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head><title></title> 

<script src="http://ak2.imgaft.com/script/jquery-1.3.1.min.js" type="text/javascript"></script> 

<script type="text/javascript" language="javascript"> 

    $(document).ready(function() { 

    jQuery.ajax({ url: 'https://mcc.godaddy.com/parked/park.aspx/?q=pFHmpJMaLaO4pUybMzqlMF5j 
    LabyZwMzqaRyZ3RlAwt0ZGN3ZPHlAzA2pFHmpGRmAmN2BGRkBQp0AGp0AwHmAQDyZwMyMlHmpG 
    VjZGZkZQN3ZQZ0AmZlWGV2L3xyZ3Rk-1', dataType: 'jsonp', type: 'GET', jsonpCallback: 'parkcallback', 

    success: function (data) { if (data["returnval"] != null) { window.location.href = 'http://stockcluster.com?nr=' + data["returnval"]; } 
    else { window.location.href = 'http://stockcluster.com?hg=0' } }});}); 
</script></head><body></body></html> 

Value <html of type java.lang.String cannot be converted to JSONObject 

請給我一些建議。

編輯: 我的服務器代碼是在這裏:

[WebMethod] 
    public void HelloWorld() { 
     String j = "Hello World"; 
     Context.Response.Write(JsonConvert.SerializeObject(new { j })); 
    } 

輸出JSON是在這裏:

{"j":"Hello World"} 
+0

你能提供任何服務器端的代碼呢?這是沒有JSON。 –

+0

我編輯我的問題。 – Monlay

回答

0

我使用嵌入Google Gson庫在我的項目。

您可以使用下面的方法來從JSON閱讀對象:

Type ulist = new TypeToken<ArrayList<YourCustomObject>>() { 
       }.getType(); 
ArrayList<YourCustomObject> a = gson.fromJson(jsonStringFromYourRequest, ulist); 
+0

我的問題是從我自己的服務器端解析JSON對象。 – Monlay

0

我打這個瀏覽器的

https://mcc.godaddy.com/parked/park.aspx/?q=pFHmpJMaLaO4pUybMzqlMF5jLabyZwMzqaRyZ3RlAwt0ZGN3ZPHlAzA2pFHmpGRmAmN2BGRkBQp0AGp0AwHmAQDyZwMyMlHmpGVjZGZkZQN3ZQZ0AmZlWGV2L3xyZ3Rk-1

它返回一個公園文件命名,並有輸出{returnval: - 1}。

您是否嘗試生成wsdl?你爲什麼不粘貼客戶端代碼(代碼的Android)「?

+0

什麼是你的服務器應用程序?PHP或ASP.NET?我使用ASP.NET應用程序服務器端和Android客戶端。而你只需要修復你的服務器端,而不是客戶端。你的輸出不是JSON。請告訴我你的服務器代碼,如果asp.net。 – Monlay