Question

i have been trying to find a way to deserialize this in C# but unfortunately without luck,,

i would really appreciate it if someone can help, here is the json data:

{
"138c399": [
    "A1E67B",
    39.826,
    -76.9241,
    238,
    15400,
    402,
    "2573",
    "T-KDCA1",
    "B772",
    "N221UA",
    1367747636,
    "KWI",
    "IAD",
    "UA981",
    0,
    -1280,
    "UAL981",
    1367748699
],
"138c3c8": [
    "89911F",
    45.3878,
    25.8222,
    290,
    35975,
    460,
    "2362",
    "T-LROP1",
    "B744",
    "B-18711",
    1367747646,
    "TPE",
    "FRA",
    "CI5621",
    0,
    0,
    "CAL5621",
    1367754205
],
"full_count": 3796,
"version": 4

}

EDIT: I changed the json data

Was it helpful?

Solution 3

Are you looking for something like this :) (Using Json.Net)

var flights = JObject.Parse(json)
                .Children().Cast<JProperty>()
                .Select(p => new { Key = p.Name, Values = p.Value.ToArray() })
                .Select(j => new 
                {
                    id = j.Key,
                    hex = (string)j.Values[0],
                    lat = double.Parse(j.Values[1].ToString(), CultureInfo.InvariantCulture),
                    lon = double.Parse(j.Values[2].ToString(), CultureInfo.InvariantCulture),
                    dir = (int)j.Values[3],
                    alt = (int)j.Values[4],
                    speed = (int)j.Values[5],
                    radar = (string)j.Values[7],
                    plane = (string)j.Values[8],
                    reg = (string)j.Values[9],
                    time = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Add(TimeSpan.FromSeconds((int)j.Values[10])),
                    from = (string)j.Values[11],
                    to = (string)j.Values[12],
                    callsign = (string)j.Values[13],
                })
                .ToList();

OTHER TIPS

Try JavaScriptSerializer class

var _object = JavaScriptSerializer.Deserialize<dynamic>(yourJSON);

Try http://james.newtonking.com/pages/json-net.aspx, awesome class for all stuff regarding seralize and deserialize json, xml into objects and vice versa.

I'd go with Json.NET as YvesR suggested, it is in fact used by Microsoft as well these days (in ASP.NET MVC Web API) - they essentially tossed the support for their internal JSON serialization technology (i.e. JavaScriptSerializer).

Here is the worth reading article on JSON Serialization and Deserialization. Hope this will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top