Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 不使用节点名反序列化JSON_C#_Json - Fatal编程技术网

C# 不使用节点名反序列化JSON

C# 不使用节点名反序列化JSON,c#,json,C#,Json,我有这个JSON,我找不到反序列化它的方法。第一个“子节点”中的MAC地址没有名称存在问题。所以,我不知道如何构造反序列化类 { 'nodes': { '00:00:00:00:00:00:00:9D': { 'node_id': 1, 'rssi': 12, 'temperature': 26, 'pressure': 995, 'humidity':

我有这个JSON,我找不到反序列化它的方法。第一个“子节点”中的MAC地址没有名称存在问题。所以,我不知道如何构造反序列化类

{
    'nodes': {
        '00:00:00:00:00:00:00:9D': {
            'node_id': 1,
            'rssi': 12,
            'temperature': 26,
            'pressure': 995,
            'humidity': 26,
            'gas_resistance': 465341,
            'iaq': 1
        }
    }
}

您可以使用
词典
,例如:

public class Root
{
    public Dictionary<string, Node> Nodes { get; set; }
}

public class Node
{
    [JsonProperty("node_id")]
    public string NodeId { get; set; }

    // The other properties are left for you to fill out...
}
公共类根目录
{
公共字典节点{get;set;}
}
公共类节点
{
[JsonProperty(“节点id”)]
公共字符串NodeId{get;set;}
//其他属性留给您填写。。。
}
然后像这样反序列化:

var result = JsonConvert.DeserializeObject<Root>(json);
var result=JsonConvert.DeserializeObject(json);

如果您使用的是JSON.NET,您可以使用。这是否回答了您的问题?而
节点
有一个S,但返回一个对象。。当存在多个对象时,它可能返回一个数组。在这种情况下=>更清晰的重复。