我创建了一个REST API,但是当我用GET调用它,它返回:REST API响应包括“这个XML文件没有出现......”
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ArrayOfgetSiteList xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Thor">
<getSiteList>
<responseCode>1</responseCode>
<responseMessage>No message</responseMessage>
<sites>
<Sites>
<siteAddress>11 Main Street054656</siteAddress>
<siteId>1</siteId>
<siteName>Sky Towers</siteName>
</Sites>
<Sites>
<siteAddress>1 Grande Street</siteAddress>
<siteId>2</siteId>
<siteName>Hotel Grande</siteName>
</Sites>
</sites>
</getSiteList>
</ArrayOfgetSiteList>
我如何得到它只返回方括号内的JSON文本,而不是“This XML file ...”部分?是否有一些标题我应该添加到响应中,如果有的话,我在哪里添加它?
此外,我怎样才能得到它格式化/像http://echo.jsontest.com/key/value/mykey/myvalue/anotherkey/anothervalue很好地缩进?
感谢您的帮助。
这不是xml ...这是JSON。你究竟如何输出这个json?如果它像'header('Content-type:text/xml');回声json_encode($ arr);',那么你得到了你告诉系统要做的事情:输出json和谎言,它是xml。 –
这是因为XML是JSON ... – War10ck
我没有故意添加任何标题。我遵循http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/using-web-api-with-aspnet-web-forms并输出JSON作为列表。我应该在哪里添加标题?当我在Postman上运行它时,它给了我正在寻找的JSON输出。但是当我在网络浏览器(Chrome)上运行它时,会出现上述输出。 – Windhoek