{
"success": true,
"items": {
"\u2605 Bayonet": {
"name": "\u2605 Bayonet",
"safe_price": "118.31",
"safe_net_price": "110.60",
"ongoing_price_manipulation": false,
"total_volume": 3148,
"7_days": {
"median_price": "118.31",
"median_net_price": "110.60",
"average_price": "118.25",
"average_net_price": "102.84",
"lowest_price": "100.00",
"lowest_net_price": "86.97",
"highest_price": "132.25",
"highest_net_price": "115.00",
"mean_absolute_deviation": "5.46",
"deviation_percentage": 0.046173361522199,
"trend": -0.050389739620763,
"volume": 94
},
"30_days": {
"median_price": "138.94",
"median_net_price": "129.88",
"average_price": "135.69",
"average_net_price": "118.00",
"lowest_price": "56.03",
"lowest_net_price": "48.73",
"highest_price": "156.60",
"highest_net_price": "136.19",
"mean_absolute_deviation": "10.81",
"deviation_percentage": 0.079666887758862,
"trend": -0.23473444256315,
"volume": 422
},
"all_time": {
"median_price": "148.00",
"median_net_price": "138.35",
"average_price": "147.33",
"average_net_price": "128.12",
"lowest_price": "0.17",
"lowest_net_price": "0.15",
"highest_price": "179.24",
"highest_net_price": "155.87",
"mean_absolute_deviation": "9.02",
"deviation_percentage": 0.061223104595127,
"trend": -0.032006931201406,
"volume": 3148
},
"first_seen": 1444261666
},
// etc ...
"\u2605 Bayonet | Bright Water (Battle-Scarred)": {
"name": "\u2605 Bayonet | Bright Water (Battle-Scarred)",
"safe_price": "81.21",
"safe_net_price": "70.62",
"ongoing_price_manipulation": false,
"total_volume": 1,
"7_days": {
"volume": 0
},
"30_days": {
"median_price": "81.21",
"median_net_price": "70.62",
"average_price": "81.21",
"average_net_price": "70.62",
"lowest_price": "81.21",
"lowest_net_price": "70.62",
"highest_price": "81.21",
"highest_net_price": "70.62",
"mean_absolute_deviation": "0.00",
"deviation_percentage": 0,
"trend": 0,
"volume": 1
},
"all_time": {
"median_price": "81.21",
"median_net_price": "70.62",
"average_price": "81.21",
"average_net_price": "70.62",
"lowest_price": "81.21",
"lowest_net_price": "70.62",
"highest_price": "81.21",
"highest_net_price": "70.62",
"mean_absolute_deviation": "0.00",
"deviation_percentage": 0,
"trend": 0,
"volume": 1
},
"first_seen": 1466590845
},
// etc ...
"XM1014 | VariCamo Blue (Well-Worn)": {
"name": "XM1014 | VariCamo Blue (Well-Worn)",
"safe_price": "0.89",
"safe_net_price": "0.84",
"ongoing_price_manipulation": false,
"total_volume": 763,
"7_days": {
"median_price": "0.89",
"median_net_price": "0.84",
"average_price": "0.90",
"average_net_price": "0.80",
"lowest_price": "0.65",
"lowest_net_price": "0.58",
"highest_price": "1.08",
"highest_net_price": "0.95",
"mean_absolute_deviation": "0.09",
"deviation_percentage": 0.1,
"trend": -0.10752688172043,
"volume": 30
},
"30_days": {
"median_price": "1.12",
"median_net_price": "0.99",
"average_price": "1.10",
"average_net_price": "0.96",
"lowest_price": "0.65",
"lowest_net_price": "0.58",
"highest_price": "1.51",
"highest_net_price": "1.32",
"mean_absolute_deviation": "0.16",
"deviation_percentage": 0.14545454545455,
"trend": -0.32851070467574,
"volume": 153
},
"all_time": {
"median_price": "1.70",
"median_net_price": "1.49",
"average_price": "1.71",
"average_net_price": "1.50",
"lowest_price": "0.03",
"lowest_net_price": "0.01",
"highest_price": "11.50",
"highest_net_price": "10.00",
"mean_absolute_deviation": "0.41",
"deviation_percentage": 0.23976608187135,
"trend": -0.67071929583276,
"volume": 763
},
"first_seen": 1444277043
}
},
"build_time": 19954,
"updated_at": 1467408505
}
我在“项目”中每个新项目都有一个新名称的那一刻感到困惑。目前这就是我所拥有的:
public class 7Days
{
public string median_price { get; set; }
public string median_net_price { get; set; }
public string average_price { get; set; }
public string average_net_price { get; set; }
public string lowest_price { get; set; }
public string lowest_net_price { get; set; }
public string highest_price { get; set; }
public string highest_net_price { get; set; }
public string mean_absolute_deviation { get; set; }
public double deviation_percentage { get; set; }
public double trend { get; set; }
public int volume { get; set; }
}
public class 30Days
{
public string median_price { get; set; }
public string median_net_price { get; set; }
public string average_price { get; set; }
public string average_net_price { get; set; }
public string lowest_price { get; set; }
public string lowest_net_price { get; set; }
public string highest_price { get; set; }
public string highest_net_price { get; set; }
public string mean_absolute_deviation { get; set; }
public double deviation_percentage { get; set; }
public double trend { get; set; }
public int volume { get; set; }
}
public class AllTime
{
public string median_price { get; set; }
public string median_net_price { get; set; }
public string average_price { get; set; }
public string average_net_price { get; set; }
public string lowest_price { get; set; }
public string lowest_net_price { get; set; }
public string highest_price { get; set; }
public string highest_net_price { get; set; }
public string mean_absolute_deviation { get; set; }
public double deviation_percentage { get; set; }
public double trend { get; set; }
public int volume { get; set; }
}
public class Bayonet
{
public string name { get; set; }
public string safe_price { get; set; }
public string safe_net_price { get; set; }
public bool ongoing_price_manipulation { get; set; }
public int total_volume { get; set; }
public 7Days 7_days { get; set; }
public 30Days 30_days { get; set; }
public AllTime all_time { get; set; }
public int first_seen { get; set; }
}
public class BayonetBrightWaterBattleScarred
{
public string name { get; set; }
public string safe_price { get; set; }
public string safe_net_price { get; set; }
public bool ongoing_price_manipulation { get; set; }
public int total_volume { get; set; }
public 7_days { get; set; }
public 30_days { get; set; }
public all_time { get; set; }
public int first_seen { get; set; }
}
public class XM1014VariCamoBlueWellWorn
{
public string name { get; set; }
public string safe_price { get; set; }
public string safe_net_price { get; set; }
public bool ongoing_price_manipulation { get; set; }
public int total_volume { get; set; }
public 7_days { get; set; }
public 30_days { get; set; }
public all_time { get; set; }
public int first_seen { get; set; }
}
public class Items
{
public Bayonet ★ Bayonet { get; set; }
public BayonetBrightWaterBattleScarred ★ Bayonet | Bright Water (Battle-Scarred) { get; set; }
public XM1014VariCamoBlueWellWorn XM1014 | VariCamo Blue (Well-Worn) { get; set; }
}
public class Example
{
public bool success { get; set; }
public Items items { get; set; }
public int build_time { get; set; }
public int updated_at { get; set; }
}
但是我需要在有很多不同名称的项目的地方反序列化 json,告诉我如何避免使用每个项目名称创建类?祝大家新年快乐)))
UPD。我重做了课程,这就是发生的事情:
{
public class _7Days
{
public string median_price { get; set; }
public string median_net_price { get; set; }
public string average_price { get; set; }
public string average_net_price { get; set; }
public string lowest_price { get; set; }
public string lowest_net_price { get; set; }
public string highest_price { get; set; }
public string highest_net_price { get; set; }
public string mean_absolute_deviation { get; set; }
public double deviation_percentage { get; set; }
public double trend { get; set; }
public int volume { get; set; }
}
public class _30Days
{
public string median_price { get; set; }
public string median_net_price { get; set; }
public string average_price { get; set; }
public string average_net_price { get; set; }
public string lowest_price { get; set; }
public string lowest_net_price { get; set; }
public string highest_price { get; set; }
public string highest_net_price { get; set; }
public string mean_absolute_deviation { get; set; }
public double deviation_percentage { get; set; }
public double trend { get; set; }
public int volume { get; set; }
}
public class _AllTime
{
public string median_price { get; set; }
public string median_net_price { get; set; }
public string average_price { get; set; }
public string average_net_price { get; set; }
public string lowest_price { get; set; }
public string lowest_net_price { get; set; }
public string highest_price { get; set; }
public string highest_net_price { get; set; }
public string mean_absolute_deviation { get; set; }
public double deviation_percentage { get; set; }
public double trend { get; set; }
public int volume { get; set; }
}
public class Item
{
public string name { get; set; }
public string safe_price { get; set; }
public string safe_net_price { get; set; }
public bool ongoing_price_manipulation { get; set; }
public int total_volume { get; set; }
public _AllTime all_time { get; set; }
public _7Days _7_days { get; set; }
public _30Days _30_days { get; set; }
public int first_seen { get; set; }
}
public class Rootobject
{
public bool success { get; set; }
public Dictionary<string, Item> item { get; set; }
public int build_time { get; set; }
public int updated_at { get; set; }
}
}
创建了一个读取 json 的附加类:
public static Rootobject GetRoot()
{
string path = @"C:\Users\DB.json";
StreamReader sr = new StreamReader(path);
string itemDB = sr.ReadToEnd();
return JsonConvert.DeserializeObject<Rootobject>(itemDB);
}
在我的程序中,我调用:
Rootobject itemsDB = PricerApi.GetRoot();
但是在 itemsDB 的 item=null 字段中,虽然从文件中读取并执行反序列化时,所有项目都存在于 item 字段中,我打开并查看它们,一切都与 json 中应有的完全一样,我做了什么错误的?