这是我第一次遇到这种困难。我正在尝试使用 newtonsoft.net 用 c# 解析一个简单的 json,但我不知道如何处理此类问题。我的 json 是这种格式:
{
"events": {
"119327": {
"name": "John doe",
"start": "1524435387600",
"end": "152446565612800",
"details": "description"
"image_url": "http://go/to/url"
},
"119217": {
"name": "John doe",
"start": "1524534243387600",
"end": "15244656612800",
"details": "description"
"image_url": "http://go/to/url"
},
"14397": {
"name": "John doe",
"start": "1524386567600",
"end": "15244143242800",
"details": "description"
"image_url": "http://go/to/url"
}
}
}
现在您可以看到 id 的行为就像一个对象,也像 id 本身一样,稍后我将需要它。 谁能向我解释一下如何解决这个问题。有什么办法吗?任何帮助将不胜感激。提前致谢。
最佳答案
我会定义一些像这样的“事件”类
name
start
end
detail
image_url
然后,我会尝试反序列化events
作为Dictionary<int, Event>
.
之后,您始终可以在生成的字典上使用一些 LINQ 查询,将其映射到另一个类似于具有附加 id 字段的 Event 类的 EventWithId 类。
关于c# - 当 json 中的 id 属性充当对象时创建 POCO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49883999/