Json.NET反序列化对象始终显示为null

时间:2017-03-22 08:57:36

标签: json asp.net-mvc-4 datatable

 JsonConvert.DeserializeObject<> not working .

始终为空。

Json.NET deserializing object returns null.

以下是代码:

 JsonResult jsonresult = Json(result1, JsonRequestBehavior.AllowGet);
            User _contacts = new User();


           _contacts = JsonConvert.DeserializeObject<User>(jsonresult.Data.ToString());

jsonresult.Data.ToString()

{"recordsTotal":13,"recordsFiltered":13,"data":[{"Id":2,"Title":"Brajo testing","Type":null,"Description":null,"Importancy":null,"CreatedDate":"2017-03-16T14:31:04.41","Status":null,"Email":"+HNcbJGxLqAGmAQq9gOW1A==","Name":"Oliver Woodss"},{"Id":3,"Title":"udal testing","Type":null,"Description":null,"Importancy":null,"CreatedDate":"2017-03-16T14:31:41.253","Status":null,"Email":"+HNcbJGxLqAGmAQq9gOW1A==","Name":"Oliver Woodss"},

当我指定它时,它为空。

result = this.Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = _contacts }, JsonRequestBehavior.AllowGet);

1 个答案:

答案 0 :(得分:0)

这样做,

var response = client.GetAsync(apiUrl).Result;
var responseResult = JsonConvert.DeserializeObject<List<User>>
                    (response.Content.ReadAsStringAsync().Result);

Then you can fetch data from responseResult with a dot operator.