JsonConvert.DeserializeObject()方法不起作用

时间:2016-03-12 14:07:54

标签: c# json deserialization

我遇到了将json字符串反序列化为.net列表对象的问题。它工作了一段时间,突然因某种原因停止了。请参阅错误消息的链接

https://gyazo.com/f6ef55625ffa94060cfc900542c24e0f

json看起来像这样:

[
  {
    "project": {
  "id": 797100,
  "client_id": 339652,
  "name": "Internal LWA",
  "code": "",
  "active": false,
  "billable": false,
  "bill_by": "none",
  "hourly_rate": null,
  "budget": null,
  "budget_by": "none",
  "notify_when_over_budget": false,
  "over_budget_notification_percentage": 80,
  "over_budget_notified_at": null,
  "show_budget_to_all": false,
  "created_at": "2010-08-13T14:15:36Z",
  "updated_at": "2015-03-24T13:59:07Z",
  "starts_on": "2010-08-09",
  "ends_on": null,
  "estimate": null,
  "estimate_by": "none",
  "hint_earliest_record_at": "2010-08-09",
  "hint_latest_record_at": "2012-04-13",
  "notes": "I största möjliga mån bör all tid försöka knytas till kundprojekt. Övrig tid rapporteras här.",
  "cost_budget": null,
  "cost_budget_include_expenses": false
}
  },
  {
     "project": {
      "id": 805512,
      "client_id": 344217,
  "name": "Skräddarsydd analys",
  "code": "143-20100505",
  "active": false,
  "billable": true,
  "bill_by": "none",
  "hourly_rate": null,
  "budget": null,
  "budget_by": "project_cost",
  "notify_when_over_budget": true,
  "over_budget_notification_percentage": 80,
  "over_budget_notified_at": null,
  "show_budget_to_all": true,
  "created_at": "2010-08-20T14:52:11Z",
  "updated_at": "2015-03-24T13:59:07Z",
  "starts_on": "2010-08-09",
  "ends_on": null,
  "estimate": null,
  "estimate_by": "project_cost",
  "hint_earliest_record_at": "2010-08-09",
  "hint_latest_record_at": "2010-08-19",
  "notes": "Unik flödesanalys som besvarar frågorna: Vem köper, varför köper inte vissa och lite annat som vi är experter på.",
  "cost_budget": 50000,
  "cost_budget_include_expenses": true
}

},

2 个答案:

答案 0 :(得分:0)

你能发布你的模特吗? 似乎'updated_at'属性是一个int而不是DateTime或Nullable DateTime。

答案 1 :(得分:0)

嗯这可能很棘手,但你应该尝试检查一下你是否没有得到另一种单位类型......我看到一些非安全变量可能是错误的。你应该确保你总是得到相同的数据类型...像旧变量可以是整数类型,新变量可以是double或string或者其他类型。因为看起来这可能是你的情况。我建议你而不是你的班级尝试使用这个,让我知道:)

public class Project
{
    public string id { get; set; }
    public string client_id { get; set; }
    public string name { get; set; }
    public string code { get; set; }
    public string active { get; set; }
    public string billable { get; set; }
    public string bill_by { get; set; }
    public object hourly_rate { get; set; }
    public object budget { get; set; }
    public string budget_by { get; set; }
    public bool notify_when_over_budget { get; set; }
    public string over_budget_notification_percentage { get; set; }
    public object over_budget_notified_at { get; set; }
    public bool show_budget_to_all { get; set; }
    public string created_at { get; set; }
    public string updated_at { get; set; }
    public string starts_on { get; set; }
    public object ends_on { get; set; }
    public object estimate { get; set; }
    public string estimate_by { get; set; }
    public string hint_earliest_record_at { get; set; }
    public string hint_latest_record_at { get; set; }
    public string notes { get; set; }
    public string? cost_budget { get; set; }
    public bool cost_budget_include_expenses { get; set; }
}