2016-01-11 55 views
0

我有一個簡單的代碼,需要在瀏覽器中使用json返回字符串。Asp.net的Web服務返回XML而不是JSON瀏覽器使用http

[WebMethod] 
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
    public string FunctiGetJsononName(string str) 
    { 
     JavaScriptSerializer ser = new JavaScriptSerializer(); 
     return ser.Serialize(str); 
    } 

我得到的輸出是json在xml裏面。我想要沒有XML的json。

我也不能使用void方法。 此外,我使用框架4.5.2和空模板(我不能使用任何其他)。

回答

0
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] 
[WebMethod] 
public string FunctiGetJsononName(string str){ 

    Context.Response.Clear(); 
    Context.Response.ContentType = "application/json"; 
........ 
} 

試試這個......可能會幫助你! 它幫助我...

+0

謝謝你的評論,我試過了,我仍然得到sme結果。 – EsterSason

相關問題