Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a json response this
"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"



i have created class for this

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; }    
    }

}


But i am not able to serileze this json in this class.
in object all nodes values in null. and blank.

What I have tried:

i have tried to serialize in string. data is there but not coming in object
Posted
Updated 11-Nov-19 22:00pm
Comments
Richard MacCutchan 12-Nov-19 3:21am    
You need to provide some more details of what is going wrong.
Andy Lanng 12-Nov-19 3:48am    
First obvious issue I can see is that the whole object needs to be wrapped in curly brackets ('{}')
Member 14067523 12-Nov-19 5:56am    
i have wrapped it curly braces.json is valid. in my json my key(key name) is changing. so i am not able to make class. its look key names when we assign json to class object at runtime.In this kind of scenario what we can do?

1 solution

First off, your classes don't entirely match the JSON: if you add the appropriate curly brackets to your data to make it "valid JSON" and run it through a class generator: json2csharp - generate c# classes from json[^] then you get a load of "__invalid_type__" classes generated which means that whatever generated teh JSON didn't do a good job, or this is an abstract from a larger JSON sample that is incomplete.

I'd start by going back to the source and checking where this came from - if it's an abstract, then you need to look at abstracting it rather better!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900