1
我有.NET Web服務應該返回結果作爲JSON,但它將它作爲XML返回?這是我的代碼。.NET WebService返回XML而不是JSON
[WebService(Namespace = "http://tempuri.org/MyService")]
[ScriptService]
public class MyService : System.Web.Services.WebService
{
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<MyData> GetMyData(string dataFilter, string param)
{
if (dataFilter.ToLower() == "filterValue")
return getData(param);
return null;
}
}
public class MyData
{
public string id { get; set; }
public string name { get; set; }
protected internal MyData() { }
}
這裏是web.config中
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
<customErrors mode="Off"/>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
編輯 通過數字只有當參數,但路過的時候,它返回內部服務器錯誤Web服務工作正常參數內的字符。我很困惑:O
你的代碼返回JSON格式,但它不包含一個對象來解析它。 {[{「Test」:「200」}]}但我希望它返回{「d」:[{「Test」:「200」}]} – user987654
可以分享結果的屏幕截圖。 – Bhavanaditya