Как мне сериализовать свою строку json в объект класса
у меня есть ответ json это
"data": { "123456": { "rtc": { "121": { "rpc": { "2342_R": [ { "contract_type": "b2c", "egc": 0, "op_wt": 11798.82, "mp_wt": 11799, "mp": 9999, "tp_alltax": 11799, "op": 9999, "fwdp": { "ps": "9999|9999|1799", "ts": "2019-11-08T15:57:18", "carry_forward": ",@*`HHaa$*H" }, "ttc": 1799.82, "fcdt": "Nov 27, 2019 14:00 hours", "mpc": "CP", "amn": [ "Accommodation", "FREE Breakfast" ], "tp": 9999, "rtn": "Deluxe Twin Room with Breakfast", "ibp": "v3", "pay_mode": 1 } ], "2355_R": [ { "contract_type": "b2c", "egc": 0, "op_wt": 9438.82, "mp_wt": 9439, "mp": 7999, "tp_alltax": 9439, "op": 7999, "fwdp": { "ps": "7999|7999|1439", "ts": "2019-11-08T15:57:18", "carry_forward": ",,$PRR*--" }, "ttc": 1439.82, "fcdt": "Nov 27, 2019 14:00 hours", "mpc": "EP", "amn": [ "Accommodation only" ], "tp": 7999, "rtn": "Deluxe Twin Room", "ibp": "v3", "pay_mode": 1 } ], "34434": [ { "contract_type": "b2c", "egc": 0, "op_wt": 8862.89, "mp_wt": 8063, "mp": 7199, "tp_alltax": 8063, "op": 7999, "fwdp": { "ps": "7999|6399|767", "ts": "2019-11-08T15:57:18", "carry_forward": "aZ.a!a|KH" }, "ttc": 863.89, "fcdt": "", "mpc": "EP", "amn": [ "Accommodation only" ], "tp": 7199, "rtn": "Deluxe Twin Room", "ibp": "v3", "pay_mode": 1 } ], "23244": [ { "contract_type": "b2c", "egc": 0, "op_wt": 11212.14, "mp_wt": 10247, "mp": 8684, "tp_alltax": 10247, "op": 9649, "fwdp": { "ps": "9649|8684|1563", "ts": "2019-11-08T15:57:18", "carry_forward": "Ha`**RK$$aR" }, "ttc": 1563.14, "fcdt": "", "mpc": "CP", "amn": [ "Accommodation", "FREE Breakfast" ], "tp": 8684, "rtn": "Deluxe Twin Room with Breakfast", "ibp": "v3", "pay_mode": 1 } ] } }, "345": { "rpc": { "234_R": [ { "contract_type": "b2c", "egc": 0, "op_wt": 14335.82, "mp_wt": 14336, "mp": 12149, "tp_alltax": 14336, "op": 12149, "fwdp": { "ps": "12149|12149|2186", "ts": "2019-11-08T15:57:18", "carry_forward": "Za$Pa@`|$-H" }, "ttc": 2186.82, "fcdt": "Nov 27, 2019 14:00 hours", "mpc": "CP", "amn": [ "Accommodation", "FREE Breakfast" ], "tp": 12149, "rtn": "Executive Room with Breakfast", "ibp": "v3", "pay_mode": 1 } ], "2344_R": [ { "contract_type": "b2c", "egc": 0, "op_wt": 12388.82, "mp_wt": 12389, "mp": 10499, "tp_alltax": 12389, "op": 10499, "fwdp": { "ps": "10499|10499|1889", "ts": "2019-11-08T15:57:18", "carry_forward": ",!|*a@+.$$a" }, "ttc": 1889.82, "fcdt": "Nov 27, 2019 14:00 hours", "mpc": "EP", "amn": [ "Accommodation only" ], "tp": 10499, "rtn": "Executive Room", "ibp": "v3", "pay_mode": 1 } ], "345454545": [ { "contract_type": "b2c", "egc": 0, "op_wt": 12199.84, "mp_wt": 11150, "mp": 9449, "tp_alltax": 11150, "op": 10499, "fwdp": { "ps": "10499|9449|1700", "ts": "2019-11-08T15:57:18", "carry_forward": "!!-a$*a+$H@" }, "ttc": 1700.84, "fcdt": "", "mpc": "EP", "amn": [ "Accommodation only" ], "tp": 9449, "rtn": "Executive Room", "ibp": "v3", "pay_mode": 1 } ], "23535": [ { "contract_type": "b2c", "egc": 0, "op_wt": 14117.14, "mp_wt": 12902, "mp": 10934, "tp_alltax": 12902, "op": 12149, "fwdp": { "ps": "12149|10934|1968", "ts": "2019-11-08T15:57:18", "carry_forward": "*RKK,!+-$ZR" }, "ttc": 1968.14, "fcdt": "", "mpc": "CP", "amn": [ "Accommodation", "FREE Breakfast" ], "tp": 10934, "rtn": "Executive Room with Breakfast", "ibp": "v3", "pay_mode": 1 } ] } }, "234343": { "rpc": { "44454_R": [ { "contract_type": "b2c", "egc": 0, "op_wt": 18878.82, "mp_wt": 18879, "mp": 15999, "tp_alltax": 18879, "op": 15999, "fwdp": { "ps": "15999|15999|2879", "ts": "2019-11-08T15:57:18", "carry_forward": ",$PK@H|`$!a" }, "ttc": 2879.82, "fcdt": "Nov 27, 2019 14:00 hours", "mpc": "EP", "amn": [ "Accommodation only" ], "tp": 15999, "rtn": "Suite Room", "ibp": "v3", "pay_mode": 1 } ], "45453_R": [ { "contract_type": "b2c", "egc": 0, "op_wt": 21415.82, "mp_wt": 21416, "mp": 18149, "tp_alltax": 21416, "op": 18149, "fwdp": { "ps": "18149|18149|3266", "ts": "2019-11-08T15:57:18", "carry_forward": "Z!a+Raa+*HR" }, "ttc": 3266.82, "fcdt": "Nov 27, 2019 14:00 hours", "mpc": "CP", "amn": [ "Accommodation", "FREE Breakfast" ], "tp": 18149, "rtn": "Suite Room with Breakfast", "ibp": "v3", "pay_mode": 1 } ], "453453": [ { "contract_type": "b2c", "egc": 0, "op_wt": 20508.14, "mp_wt": 18743, "mp": 15884, "tp_alltax": 18743, "op": 17649, "fwdp": { "ps": "17649|15884|2859", "ts": "2019-11-08T15:57:18", "carry_forward": "a*`aH@|P$@a" }, "ttc": 2859.14, "fcdt": "", "mpc": "CP", "amn": [ "Accommodation", "FREE Breakfast" ], "tp": 15884, "rtn": "Suite Room with Breakfast", "ibp": "v3", "pay_mode": 1 } ], "43554": [ { "contract_type": "b2c", "egc": 0, "op_wt": 18590.84, "mp_wt": 16991, "mp": 14399, "tp_alltax": 16991, "op": 15999, "fwdp": { "ps": "15999|14399|2591", "ts": "2019-11-08T15:57:18", "carry_forward": "$@*$,R.|$*Z" }, "ttc": 2591.84, "fcdt": "", "mpc": "", "amn": [], "tp": 14399, "rtn": "Suite Room", "ibp": "v3", "pay_mode": 1 } ] } }, "434": { "rpc": { "43445_R": [ { "contract_type": "b2c", "egc": 0, "op_wt": 10913.82, "mp_wt": 10914, "mp": 9249, "tp_alltax": 10914, "op": 9249, "fwdp": { "ps": "9249|9249|1664", "ts": "2019-11-08T15:57:18", "carry_forward": "RRa$,-K.$Z-" }, "ttc": 1664.82, "fcdt": "Nov 27, 2019 14:00 hours", "mpc": "EP", "amn": [ "Accommodation only" ], "tp": 9249, "rtn": "Deluxe Double Room", "ibp": "v3", "pay_mode": 1 } ], "56546": [ { "contract_type": "b2c", "egc": 0, "op_wt": 10166.34, "mp_wt": 9291, "mp": 7874, "tp_alltax": 9291, "op": 8749, "fwdp": { "ps": "8749|7874|1417", "ts": "2019-11-08T15:57:18", "carry_forward": "$**P*Z*$$" }, "ttc": 1417.34, "fcdt": "", "mpc": "EP", "amn": [ "Accommodation only" ], "tp": 7874, "rtn": "Deluxe Double Room", "ibp": "v3", "pay_mode": 1 } ], "6456456_R": [ { "contract_type": "b2c", "egc": 0, "op_wt": 13273.82, "mp_wt": 13274, "mp": 11249, "tp_alltax": 13274, "op": 11249, "fwdp": { "ps": "11249|11249|2024", "ts": "2019-11-08T15:57:18", "carry_forward": "RaP+*!$+$$H" }, "ttc": 2024.82, "fcdt": "Nov 27, 2019 14:00 hours", "mpc": "CP", "amn": [ "Accommodation", "FREE Breakfast" ], "tp": 11249, "rtn": "Deluxe Double Room with Breakfast", "ibp": "v3", "pay_mode": 1 } ], "5654654": [ { "contract_type": "b2c", "egc": 0, "op_wt": 12083.64, "mp_wt": 11044, "mp": 9359, "tp_alltax": 11044, "op": 10399, "fwdp": { "ps": "10399|9359|1684", "ts": "2019-11-08T15:57:18", "carry_forward": "R$`K!,a$$a!" }, "ttc": 1684.64, "fcdt": "", "mpc": "CP", "amn": [ "Accommodation", "FREE Breakfast" ], "tp": 9359, "rtn": "Deluxe Double Room with Breakfast", "ibp": "v3", "pay_mode": 1 } ] } } }, "hc": "1521351329634574589", "hn": "Krishna Palace Hotel", "priority": 101, "gstn_assured": false, "dnd": true, "corporate": false } }, "is_intl": false, "success": true, "warning": "Could not fetch all the Hotels requested", "code": "1002"
я создал класс для этого
using Newtonsoft.Json; using System; using System.Collections.Generic; namespace Connector.Hotel.Expedia.Availability.Proxy { public class AvailabilityRS { [JsonProperty("data")] public DataRTC data { get; set; } [JsonProperty("is_intl")] public bool is_intl { get; set; } [JsonProperty("success")] public bool success { get; set; } [JsonProperty("warning")] public bool warning { get; set; } [JsonProperty("Code")] public bool Code { get; set; } } public class Fwdp { [JsonProperty("ps")] public string ps { get; set; } [JsonProperty("ts")] public DateTime ts { get; set; } [JsonProperty("carry_forward")] public string carry_forward { get; set; } } public class RPC { [JsonProperty("data2")] public Dictionary<string, rpcFullPlan> data2 { get; set; } } public class rpcFullPlan { [JsonProperty("contract_type")] public string contract_type { get; set; } [JsonProperty("egc")] public int egc { get; set; } [JsonProperty("op_wt")] public double op_wt { get; set; } [JsonProperty("mp_wt")] public int mp_wt { get; set; } [JsonProperty("mp")] public int mp { get; set; } [JsonProperty("tp_alltax")] public int tp_alltax { get; set; } [JsonProperty("op")] public int op { get; set; } [JsonProperty("fwdp")] public Fwdp fwdp { get; set; } [JsonProperty("ttc")] public double ttc { get; set; } [JsonProperty("fcdt")] public string fcdt { get; set; } [JsonProperty("mpc")] public string mpc { get; set; } [JsonProperty("amn")] public List<string> amn { get; set; } [JsonProperty("tp")] public int tp { get; set; } [JsonProperty("rtn")] public string rtn { get; set; } [JsonProperty("ibp")] public string ibp { get; set; } [JsonProperty("pay_mode")] public int pay_mode { get; set; } } public class RTC { [JsonProperty("data")] public Dictionary<string, RPC> data { get; set; } } public class DataRTC { [JsonProperty("data1")] public Dictionary<string, RTC> data1 { get; set; } [JsonProperty("hc")] public string hc { get; set; } [JsonProperty("hn")] public string hn { get; set; } [JsonProperty("priority")] public int priority { get; set; } [JsonProperty("gstn_assured")] public bool gstn_assured{ get; set; } [JsonProperty("dnd")] public bool dnd{ get; set; } [JsonProperty("corporate")] public bool corporate{ get; set; } } }
Но я не могу серилезировать этот json в этом классе.
в объекте все узлы имеют значения null. и пустой.
Что я уже пробовал:
я попытался сериализовать в строке. данные есть, но не поступают в объект
Richard MacCutchan
Вам нужно предоставить еще несколько подробностей о том, что происходит не так.
Andy Lanng
Первая очевидная проблема, которую я вижу, заключается в том, что весь объект должен быть заключен в фигурные скобки ('{}')
Member 14067523
я обернул его фигурными скобками.json действителен. в моем json мой ключ(имя ключа) меняется. так что я не в состоянии сделать класс. его ключевые имена выглядят, когда мы назначаем json объекту класса во время выполнения.Что мы можем сделать в таком сценарии?