【发布时间】:2020-03-30 09:05:46
【问题描述】:
在 ASMX 中编写了一个 Web 方法,以将 JSON 数据返回给 Angular 应用程序。这就是 Webmethod 的样子
[WebMethod]
[ScriptMethod(UseHttpGet =true,ResponseFormat =ResponseFormat.Json)]
public MyProjects getReport(int reportId)
{
}
这是我从 Angular 中调用它的方式
this.client.get('http://localhost:51071/webservice1.asmx/getReport?reportId=596',
{ withCredentials: true, responseType: 'text' })
.subscribe( (data) => console.log(data));
但问题是 Angular 应用程序接收到的数据是 XML 格式的。这就是我在那里指定文本的原因。如果我在那里指定 json,它当然会触发错误,说无效的 json 数据。
我完全不知道我做错了什么或者要改变什么来获得纯 JSON
这是控制台输出的样子
<?xml version="1.0" encoding="utf-8"?>
<Projects xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Success>true</Success>
<TotalRecords>391</TotalRecords>
<Data>
<ProjectData>
<ProjectCode>E6012</ProjectCode>
【问题讨论】:
-
对不起...确实如此。我已经试过了..
标签: c# angular asmx webmethod angular-httpclient