Valid JSON to Object in C#

I'm trying to deserialize a piece of JSON to a C# object, with little success so far. According to http://jsonlint.com/, the following string is valid JSON. However, there doesn't seem to be any variable names in it. I'm used to seeing JSON that has strings saying "objectID", "objectName" and all that. In this case, I could create a C# object with fields like objectID and objectName and just deserialize the whole thing like this: Quote deserializedProduct = JsonConvert.DeserializeObject<Product>(json);

Any suggestions about how I could do this? I don't see a way it will just deserialize into a series of jagged or nested arrays, for example. Would appreciate any help at all.

{
"ABCXYZ": {
    "Wed, Aug 29|Wed|29 Aug 12": [
        [
            "0~W~W4LOW~BND4~~1~X",
            "FR~ 812~ ~~ABC~08/29/2012 06:35~XYZ~08/29/2012 07:45~",
            "No Taxes",
            "2012-08-29 06:35",
            "2012-08-29 07:45",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 11.74
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ],
        [
            "0~W~W4LOW~BND4~~1~X",
            "FR~ 816~ ~~ABC~08/29/2012 14:55~XYZ~08/29/2012 16:05~",
            "No Taxes",
            "2012-08-29 14:55",
            "2012-08-29 16:05",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 11.74
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ],
        [
            "0~W~W4LOW~BND4~~1~X",
            "FR~ 818~ ~~ABC~08/29/2012 19:50~XYZ~08/29/2012 20:55~",
            "No Taxes",
            "2012-08-29 19:50",
            "2012-08-29 20:55",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 11.74
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ]
    ],
    "Thu, Aug 30|Thu|30 Aug 12": [
        [
            "0~W~W4LOW~BND4~~1~X",
            "FR~ 812~ ~~ABC~08/30/2012 06:35~XYZ~08/30/2012 07:45~",
            "No Taxes",
            "2012-08-30 06:35",
            "2012-08-30 07:45",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 11.74
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ],
        [
            "0~W~W4LOW~BND4~~1~X",
            "FR~ 816~ ~~ABC~08/30/2012 08:30~XYZ~08/30/2012 09:40~",
            "No Taxes",
            "2012-08-30 08:30",
            "2012-08-30 09:40",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 11.74
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ],
        [
            "0~W~W4LOW~BND4~~1~X",
            "FR~ 818~ ~~ABC~08/30/2012 22:10~XYZ~08/30/2012 23:15~",
            "No Taxes",
            "2012-08-30 22:10",
            "2012-08-30 23:15",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 11.74
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ]
    ],
    "Fri, Aug 31|Fri|31 Aug 12": [
        [
            "0~W~W4LOW~BND4~~1~X",
            "FR~ 812~ ~~ABC~08/31/2012 06:35~XYZ~08/31/2012 07:45~",
            "No Taxes",
            "2012-08-31 06:35",
            "2012-08-31 07:45",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 11.74
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ],
        [
            "0~C~C4LOW~BND4~~1~X",
            "FR~ 816~ ~~ABC~08/31/2012 13:20~XYZ~08/31/2012 14:30~",
            "No Taxes",
            "2012-08-31 13:20",
            "2012-08-31 14:30",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 32.74
                        }
                    ]
                }
            ],
            2,
            0,
            0,
            0
        ],
        [
            "0~C~C4LOW~BND4~~1~X",
            "FR~ 818~ ~~ABC~08/31/2012 19:50~XYZ~08/31/2012 20:55~",
            "No Taxes",
            "2012-08-31 19:50",
            "2012-08-31 20:55",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 32.74
                        }
                    ]
                }
            ],
            3,
            0,
            0,
            0
        ]
    ],
    "Sat, Sep 01|Sat|01 Sep 12": [
        [
            "0~C~C4LOW~BND4~~1~X",
            "FR~ 812~ ~~ABC~09/01/2012 08:05~XYZ~09/01/2012 09:15~",
            "No Taxes",
            "2012-09-01 08:05",
            "2012-09-01 09:15",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 32.74
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ],
        [
            "0~W~W4LOW~BND4~~1~X",
            "FR~ 818~ ~~ABC~09/01/2012 17:00~XYZ~09/01/2012 18:05~",
            "No Taxes",
            "2012-09-01 17:00",
            "2012-09-01 18:05",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 11.74
                        }
                    ]
                }
            ],
            2,
            0,
            0,
            0
        ]
    ],
    "Sun, Sep 02|Sun|02 Sep 12": [
        [
            "0~N~N16SEP~FCCG~~3~X",
            "FR~ 812~ ~~ABC~09/02/2012 06:35~XYZ~09/02/2012 07:45~",
            "No Taxes",
            "2012-09-02 06:35",
            "2012-09-02 07:45",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 9.75
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ],
        [
            "0~H~H4LOW~BND4~~1~X",
            "FR~ 816~ ~~ABC~09/02/2012 14:55~XYZ~09/02/2012 16:05~",
            "No Taxes",
            "2012-09-02 14:55",
            "2012-09-02 16:05",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 23.74
                        }
                    ]
                }
            ],
            1,
            0,
            0,
            0
        ],
        [
            "0~K~K4LOW~BND4~~1~X",
            "FR~ 818~ ~~ABC~09/02/2012 20:25~XYZ~09/02/2012 21:30~",
            "Regular Fare",
            "2012-09-02 20:25",
            "2012-09-02 21:30",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "Tax": 36,
                            "FarePrice": 33.99
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ]
    ],
    "Mon, Sep 03|Mon|03 Sep 12": [
        [
            "0~N~N16SEP~FCCG~~3~X",
            "FR~ 812~ ~~ABC~09/03/2012 06:35~XYZ~09/03/2012 07:45~",
            "No Taxes",
            "2012-09-03 06:35",
            "2012-09-03 07:45",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 9.75
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ],
        [
            "0~A~A4LOW~BND4~~1~X",
            "FR~ 818~ ~~ABC~09/03/2012 14:35~XYZ~09/03/2012 15:40~",
            "No Taxes",
            "2012-09-03 14:35",
            "2012-09-03 15:40",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "CANX": 2,
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 17.74
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ],
        [
            "0~N~N16SEP~FCCG~~3~X",
            "FR~ 816~ ~~ABC~09/03/2012 22:55~XYZ~09/03/2012 23:59~",
            "No Taxes",
            "2012-09-03 22:55",
            "2012-09-03 23:59",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 9.75
                        }
                    ]
                }
            ],
            3,
            0,
            0,
            0
        ]
    ],
    "Tue, Sep 04|Tue|04 Sep 12": [
        [
            "0~N~N16SEP~FCCG~~3~X",
            "FR~ 812~ ~~ABC~09/04/2012 06:35~XYZ~09/04/2012 07:45~",
            "No Taxes",
            "2012-09-04 06:35",
            "2012-09-04 07:45",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 9.75
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ],
        [
            "0~N~N16SEP~FCCG~~3~X",
            "FR~ 818~ ~~ABC~09/04/2012 19:50~XYZ~09/04/2012 20:55~",
            "No Taxes",
            "2012-09-04 19:50",
            "2012-09-04 20:55",
            [
                {
                    "ADT": [
                        1,
                        "0.00",
                        "0",
                        {
                            "WC": 6,
                            "ETS": 0.25,
                            "FarePrice": 9.75
                        }
                    ]
                }
            ],
            -1,
            0,
            0,
            0
        ]
    ]
}

}


var obj = (JObject)JsonConvert.DeserializeObject(json);

foreach (JProperty item in obj["ABCXYZ"].Children())
{
    Console.WriteLine(item.Name);
    foreach (var x in item)
    {
        foreach (var y in x)
        {
            Console.WriteLine("t==> " + y[0]);
        }
    }
}

PS: your json is hard to read. Json Viewer can help to see the structure of it easily.

链接地址: http://www.djcxy.com/p/6458.html

上一篇: JSON语法是否允许重复值?

下一篇: 在C#中将有效的JSON转换为对象