无法为从服务接收到的JSON响应创建映射对象/响应模型。
尝试创建自定义JsonConverter,但找不到任何合适的方法来帮助解决反序列化问题
以下是我从服务获得的JSON响应。
{
"$base": "Collection",
"nodeType": "PROTOCOL",
"Smart Building 0": {
"$base": "Collection",
"nodeType": "NETWORK",
"truncated": "true"
},
"Smart Building 1": {
"$base": "Collection",
"nodeType": "NETWORK",
"truncated": "true"
},
"Smart Building 2": {
"$base": "Collection",
"nodeType": "NETWORK",
"truncated": "true"
}
}
示例1:-相同的服务可以返回以下JSON格式
{
"$base": "Collection",
"nodeType": "PROTOCOL",
"Smart Building 0": {
"$base": "Collection",
"nodeType": "NETWORK",
"truncated": "true"
},
"Smart Building 1": {
"$base": "Collection",
"nodeType": "NETWORK",
"truncated": "true"
}
}
创建c#根对象类,以便可以轻松地将其反序列化 使用JsonConvert
答案 0 :(得分:0)
尝试这个:
public class Root : Dictionary<string, Building>
{
[JsonProperty("$base")]
public string Base { get; set; }
[JsonProperty("nodeType")]
public string NodeType { get; set; }
}
public class Building
{
[JsonProperty("$base")]
public string Base { get; set; }
[JsonProperty("nodeType")]
public string NodeType { get; set; }
[JsonProperty("truncated")]
public string Truncated { get; set; }
}