6

I am trying to deserialize the following JSon string so that I can capture the values in a b c d ...

{
   "2012-11-26 20:34:12": {
    "a": 65,
    "b": -1,
    "c": "2012-11-26 20:34:12",
    "d": -1,
    "e": 0,
    "f": -112.3211156215747,
    "g": 33.57955864376957
  }
}

JSonlint says that is valid JSon data, but what kind of class would I create in C# to use the JSON.NET JsonConverter to deserialize it ?

I am going to get more data like this and the key will vary ( currently shown as "2012-11-26 20:34:12" ) which is the part that is confusing me.

Any sample code to get me started would be greatly appreciated

1 Answer 1

4

You don't need any class

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

var dict = obj.First.First.Children().Cast<JProperty>()
            .ToDictionary(p => p.Name, p =>p.Value);

var dt =  (string)dict["c"];
var d = (double)dict["g"];
Sign up to request clarification or add additional context in comments.

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.