pookie
pookie

Reputation: 4142

JSON.net deserialize JSON without schema

I have some JSON:

{
    "739c39e": [7866679, 31.96051, 117.13700, 310, 30100, 408, 20515, 2955, "A319", "B-6429", 1440504861, "SHA", "XIY", "MU2168", 0, 0, "CES2168", 0],   
    "739d433": [5242971, 51.46741, -0.48536, 270, 0, 16, 0, 2529, "A320", "T7-MRD", 1440504861, "LHR", "BEY", "ME202", 1, 0, "MEA202", 0]
}

I am trying to deserialize this, but am not having much luck.

I've tried:

 var definition = new { a = "", b = "", c = "", d = "", e = "", f = "", g = "", h = "", i = "", j = "", k = "", l = "", m = "", n = "", o = "", p = "", q = "", r = "" };
 var jsonData = @File.ReadAllText(@filepathToData);
 dynamic deserializedData = JsonConvert.DeserializeAnonymousType(jsonData, definition);

I never expected that to work, really, as there is no "definition" in the JSON. I have also tried the JArray.Parse(jsonData); way, but I get nothing.

I've also tried JsonConvert.DeserializeObject(jsonData); but that does not return anything... or at least I am unable to inspect the returned object with Visual Studio (2015).

Does anyone have any ideas?

I'm doing this in Unity3D, if it makes any difference.

Upvotes: 3

Views: 2914

Answers (2)

panshu
panshu

Reputation: 58

You can try this

var o = JsonConvert.DeserializeObject<Dictionary<string, object[]>>(json);
o.Dump();

Upvotes: 4

stefankmitph
stefankmitph

Reputation: 3306

You could deserialize it into a dynamic object like this:

dynamic o = JsonConvert.DeserializeObject(json);
Console.WriteLine(o["739c39e"]);
Console.WriteLine(o["739c39e"][3]); // output: 310

Upvotes: 2

Related Questions