我創建了一個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