使用JSON.NET反序列化JSon字符串

时间:2022-08-23 09:46:05

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

我试图反序列化以下JSon字符串,以便我可以捕获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 ?

JSonlint说这是有效的JSon数据,但是我在C#中创建什么类来使用JSON.NET JsonConverter对其进行反序列化?

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.

我将获得更多这样的数据,密钥会有所不同(目前显示为“2012-11-26 20:34:12”),这是令我困惑的部分。

Any sample code to get me started would be greatly appreciated

任何让我入门的示例代码将不胜感激

1 个解决方案

#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"];

#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"];