Hi I am using an asp.net MVC controller to query a third party REST API.
I am getting a response but it has newline characters in the response.
{\n \"from\": 1,\n \"to\": 10,\n \"total\": 500570,\n \"currentPage\": 1,\n....
I am returning this to a view and the view is not able to read it because of \n.
I am using the following code to make the call and get the result
public JsonResult Items(string search)
{
var client = new WebClient();
string url = "http://xxxxxxxxxxxxxxx/v1/products?apiKey=xxxxxxxxxx&format=json";
JsonResult json = Json(client.DownloadString(url), "text/x-json",Encoding.UTF8, JsonRequestBehavior.AllowGet );
return json;
}
In the view side following script
<script type="text/javascript">
$(function () {
$('#searchlink').click(function () {
$.getJSON("Item/Items", $("#search").val(), getitems);
});
});
function getitems(responses) {
alert(responses);
$.each(responses, function (index, response) {
// do stuff
});
}
</script>
What am I doing wrong here?