Json到C#用Newtonsoft.Json反序列化

时间:2017-07-24 19:24:13

标签: c# asp.net json json.net json-deserialization

我有这样的json字符串。

{
  "pax": {
    "children_ages": [
      7,
      0
    ],
    "adult_quantity": 2
  },
  "room_category": "Standard",
  "room_description": "FAMILY ROOM STANDARD",
  "nightly_prices": {
    "2017-08-17": "217.81",
    "2017-08-18": "217.81",
    "2017-08-19": "217.81",
    "2017-08-20": "217.81",
    "2017-08-21": "217.81",
    "2017-08-22": "217.78"
  },
  "room_type": "DB"
}

在我从中创建c#类之后,我可以获得以下类型的类。

    public class Pax
{
    public List<int> children_ages { get; set; }
    public int adult_quantity { get; set; }
}

public class NightlyPrices
{
    public string __invalid_name__2017-08-17 { get; set; }
    public string __invalid_name__2017-08-18 { get; set; }
    public string __invalid_name__2017-08-19 { get; set; }
    public string __invalid_name__2017-08-20 { get; set; }
    public string __invalid_name__2017-08-21 { get; set; }
    public string __invalid_name__2017-08-22 { get; set; }
}

public class RootObject
{
    public Pax pax { get; set; }
    public string room_category { get; set; }
    public string room_description { get; set; }
    public NightlyPrices nightly_prices { get; set; }
    public string room_type { get; set; }
}

但是今晚的价格是动态的。

"nightly_prices": {
        "2018-08-17": "217.81",
        "2017-08-18": "217.81",
        "2018-08-19": "217.81",
        "2018-08-20": "217.81",
        "2017-08-21": "217.81",
        "2017-08-22": "217.78"
      },

当响应更改后,我无法在反序列化过程后检索nightly_prices的数据。

我已经通过添加字典类型尝试了这一点。但它不能正常工作。

有没有不同的方法来处理这种情况?

0 个答案:

没有答案
相关问题