在C#中反序列化json字典 [英] Deserializing json dictionary in C#

查看:252
本文介绍了在C#中反序列化json字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自RestSharp响应的json字符串。



json字符串如下所示:

Quote:

{Name1:sample1,Name2:sample2,Name3:Sample3}





我试图用以下代码反序列化它:

 string data = response.Content; 
Dictionary< string,object> values = JsonConvert.DeserializeObject< Dictionary< string,object>>(data);





现在如何调用并获取个人密钥包含反序列化词典?



我尝试过:



 TradeNotes.Text = values。[0] [Name1]; 

解决方案

试试

 TradeNotes.Text = Convert.ToString(values [Name1]); // sample1 



它应该像 dictionaryObject [Key] 来获得


I have a json string from RestSharp response.

The json string looks like this:

Quote:

{"Name1":"sample1","Name2":"sample2","Name3":"Sample3"}



I was trying to deserialize it with the following code:

string data = response.Content;
Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(data);



Now how do I call and get individual key that is contained the the deserialized Dictionary?

What I have tried:

TradeNotes.Text = values.[0]["Name1"];

解决方案

try

TradeNotes.Text = Convert.ToString(values["Name1"]); // sample1


it should be like dictionaryObject["Key"] to get the Value


这篇关于在C#中反序列化json字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆