我想在ASP.net webservice中获得不带字符串节点的JSON响应。
<string xmlns="http://tempuri.org/">
[{"bookname":"Love Stories","name":"Vave Microtech","email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eb8a858287809e868a99ab9d8a9d8e86828899849f8e88839f9fc5888486" rel="noreferrer noopener nofollow">[email protected]</a>","mobile":"918010066285","address":"Sushant tower sec-56, Gurgaon (India)","nearestarea":"gurgaon"},]
</string>
最佳答案
只需将方法返回类型更改为void,并使用Response.Write()方法写入字符串,如下所示。
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void TestMethod()
{
// your actual Json
string srtJson="[{\"bookname\":\"Love Stories\"}]";
HttpContext.Current.Response.ContentType = "text/xml";
HttpContext.Current.Response.Write(srtJson);
}
关于asp.net - 如何从 json 响应中删除字符串节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29666884/