用ASMX编写了一个webmethod,将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>发布于 2020-03-30 17:48:17
是否确定您的IIS配置?
打开IIS管理器,显示IIS服务器的属性单击MIME类型,然后找到扩展名为JSON的行:文件扩展名:.json MIME类型:应用程序/json
如果找不到,请创建它。
返回到IIS服务器的属性单击处理程序映射添加脚本映射请求路径: JSON可执行文件: C:\WINDOWS\system32\inetsrv\asp.dll名称:*.json
我希望这能帮助你
https://stackoverflow.com/questions/60927212
复制相似问题