我已经创建了一个REST API但是当我用GET调用它时,它会返回:
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文本,而不是&#34;这个XML文件......&#34;部分?是否有一些标题我应该添加到响应中,如果是,我将如何/在哪里添加它?
另外,如何让它像http://echo.jsontest.com/key/value/mykey/myvalue/anotherkey/anothervalue一样格式化/缩进?
感谢您的帮助。
答案 0 :(得分:0)
您应该将PartialView()
作为Json()
返回,而不是返回ActionResult
。
return Json(someItem,JsonRequestBehavior.AllowGet);