3

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.

1
  • 1
    Your data is a Dictionary, but your defeinition is an array. So change it maybe to something like this: var definition = new Dictionary( string key, new{a = "", b......} Commented Sep 2, 2016 at 9:02

2 Answers 2

4

You can try this

var o = JsonConvert.DeserializeObject<Dictionary<string, object[]>>(json);
o.Dump();
Sign up to request clarification or add additional context in comments.

1 Comment

Nice one, thank you! @Edgaras was on the right track!
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.