【发布时间】:2019-03-17 16:55:11
【问题描述】:
我有这样的json字符串:
{
"data": [
{
"id": 1,
"name": "Bitcoin",
"symbol": "BTC",
...
"quote": {
"USD": {
"price": 9283.92,
"volume_24h": 7155680000,
"percent_change_1h": -0.152774,
"percent_change_24h": 0.518894,
"market_cap": 158055024432,
"last_updated": "2018-08-09T22:53:32.000Z"
},
"BTC": {
"price": 1,
"volume_24h": 772012,
"percent_change_1h": 0,
"percent_change_24h": 0,
"percent_change_7d": 0,
"market_cap": 17024600,
"last_updated": "2018-08-09T22:53:32.000Z"
}
}
},
// objects like previous from which i need the data
],
"status": {
"timestamp": "2018-06-02T22:51:28.209Z",
...
}
}
我如何将它反序列化成这样的模型:
public class MyModel
{
public string Name { get; set; }
public string Symbol { get; set; }
public string Price { get; set; }
public double Percent_change_1h { get; set; }
public double Percent_change_24h { get; set; }
public long Market_cap { get; set; }
public DateTime Last_updated { get; set; }
}
模型中的字段名与json字符串中的键名相同。
我是 C# 新手,我找不到任何关于我的问题的有用信息,尤其是因为这个特定的 json 字符串结构。 如果你给我任何关于这个的好链接,我会很高兴。
【问题讨论】:
-
当您有 json 字符串并希望将其转换为模型类时。然后复制该 json 并转到 C# 中的一个类,然后单击顶部的编辑菜单 > 选择性粘贴 > 将 Json 粘贴为类。它将为您的 json 字符串生成模型。
标签: c# asp.net json asp.net-mvc