简体   繁体   中英

Deserializing json string

I am having some json problems. I receive this json string that I need to convert to a C# object. But I cannot figure out how to create the class.

It's the “80” and “81” that's bothering me – it's data, not datatypes. How should the classes be defined, in order to deserialize this string using JsonConvert

Thanks.

{
    "type": "offer",
    "locations": {
        "80": [
            [0.9668122154477, 1.2264154397082],
            [0.9668122154477, 0.17307269895365],
            [1, 0.17307269895365],
            [1, 1.2264154397082]
        ],
        "81": [
            [0, 1.2264154397082],
            [0, 0.17307269895365],
            [0.50429990148833, 0.17307269895365],
            [0.50429990148833, 1.2264154397082]
        ]
    },
    "id": "edcfPmWm",
    "run_from": 1385161200,
    "run_till": 1385765999,
    "heading": "Q-line udend\u00f8rs julebelysning",
    "webshop": null
}

Here is the most basic class with just the fields that fit your needs (you'd need accessors and so on).

public class YourJsonData
{

    private string type; // could be an enum
    private string id;
    private int timestampFrom;
    private int timestampTill;
    private string heading;
    private string webshop;

    private Dictionary<int, List<List<double>>> locations;

}

NB: Are you asking for a specific class that encapsulates the List<List<double>> ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM