如何使用JayRock使用字典将Json字符串转换为对象 [英] How to convert Json String to Object with Dictionary using JayRock

查看:84
本文介绍了如何使用JayRock使用字典将Json字符串转换为对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Json字符串转换为C#中的对象. 字符串是这样的:

I want to convert a Json string to an Object in C#. the string is like this:

{"dealName":"name1","properties":{"a":"1", "b":"2"}}

我这样定义类:

public class DealInfo
{
   public string dealName;
   public Dictionary<string, string> properties;
}

然后我使用以下代码进行转换:

And I use this code to convert:

DealInfo dl = JsonConvert.Import(typeof(DealInfo), jsonString) as DealInfo;

我发现它只是转换了DealName字段,但属性计数为0. 所以有什么问题?如何解决? 非常感谢!

I found it just converted the dealName field, but the properties count is 0. So, what's the problem? How to fix it? Many thanks!

推荐答案


请尝试:

DealInfo dl = JsonConvert.DeserializeObject<DealInfo>(jsonString);

这篇关于如何使用JayRock使用字典将Json字符串转换为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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