asp.net - 如何从 json 响应中删除字符串节点

标签 asp.net web-services

我想在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/

相关文章:

ios - SoapRequest 到 iOS 上的 NSString?

php - 良好的黄金价格网络服务

c# - 使用 httpwebrequest 调用 Web 服务方法 - 无法连接到远程服务器错误

c# - 在 ASP.NET 5 中将 Razor View 呈现为字符串

asp.net - 无法访问已关闭的文件

c# - 需要帮助识别 IIS 中的细微错误……? session ?别处..?

c# - 如何在gridview中合并行

java - 使用 JAX-WS 的 SOAP header (服务器端)

c# - .NET 2.0 Web 服务 WSDL 错误元素被忽略?

c# - 如何设置隐藏代码中中继器内 anchor 标记的 href 属性?