2016-01-11 58 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

相关问题