0

I post a api to get data, the response like json format, but the Content-Type was text/html

This is my code:

public ActionResult Test(string id)
{
    var request = GetMyRequest(id);
    RestClient client = new RestClient("baseUrl");
    var result = client.Execute(request).Content;
    var result2 = JObject.Parse(result);
    return Json(result2, JsonRequestBehavior.AllowGet);
}

I got the result

enter image description here

How can i deserialize the response correctly

7
  • 1
    It would be helpful if you add the content of result before deserialization. Commented Aug 7, 2017 at 2:51
  • Are you getting only square brackets in the JSON value? Commented Aug 7, 2017 at 3:17
  • 1
    Which version of asp.net-mvc are you using? Up to 4.0 still uses JavaScriptSerializer which will not know how to serialize a JObject. To switch to Json.NET see Setting the Default JSON Serializer in ASP.NET MVC or Using JSON.NET as the default JSON serializer in ASP.NET MVC 3 - is it possible?. Or try Exception converting JSON.NET JObject to JsonResult for a single method. Commented Aug 7, 2017 at 3:17
  • @dbc I use ASP.NET MVC 5 Commented Aug 7, 2017 at 3:40
  • @ChetanRanpariya if I create a model(class) to deserialize, it work correctly(not noly square brackets) Commented Aug 7, 2017 at 3:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.