如何反序列化包含字典列表的字典
我正在编写一个 Windows Phone 应用程序,它将从服务器获取一组数据并在列表框中显示每个条目。
数据来自服务器,看起来像这样,
{
"data": [
{
"value1": 777103069782066,
"value2": "SomeString",
"value3": "TextToDisplay1"
},
{
"value1": 750050696652932,
"value2": "SomeString2",
"value3": "TextToDisplay2"
},
{
"value1": 516092242936133,
"value2": "SomeString3",
"value3": "TextToDisplay3"
}
]
}
我知道如何将数据放入这样的字典中
Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
,但它将所有数据混合到一个字典条目中(正如所料,这就是全部)。
如何获取列表中包含的每个字典 - 包含在字典“数据”中,并能够将它们存储在变量中(一个列表,每个列表条目都是一个数据字典,如上所示)?
抱歉,如果问题有点啰嗦。如果需要的话我可以澄清。
谢谢,
克里斯
I am writing a Windows Phone app that will get a set of data from a server and display each entry in a list box.
The data comes from the server looking like this
{
"data": [
{
"value1": 777103069782066,
"value2": "SomeString",
"value3": "TextToDisplay1"
},
{
"value1": 750050696652932,
"value2": "SomeString2",
"value3": "TextToDisplay2"
},
{
"value1": 516092242936133,
"value2": "SomeString3",
"value3": "TextToDisplay3"
}
]
}
I know how to get the data into a dictionary like this
Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
But it mashes it all into one dictionary entry (to be expected, that's all there is).
How can I take each of the dictionaries contained in the list - contained in the dictionary "data" and be able to store them in a variable(a list, with each list entry being a dictionary of data as shown above)?
Sorry if the question is kind of wordy. I can clarify if needed.
Thanks,
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道它是否有帮助,但也许你应该将字典声明和反序列化更改为 Dictionary字符串,字典 <字符串,对象>>。
I don't know if it helps but maybe you should change your Dictionary declaration and Deserialization to Dictionary< string, Dictionary < string, object>>.