简体   繁体   English

如何使用JayRock使用字典将Json字符串转换为对象

[英]How to convert Json String to Object with Dictionary using JayRock

I want to convert a Json string to an Object in C#. 我想将Json字符串转换为C#中的对象。 the string is like this: 字符串是这样的:

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

I define the class like this: 我定义这样的类:

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;

I found it just converted the dealName field, but the properties count is 0. So, what's the problem? 我发现它只是转换了DealName字段,但是属性计数为0。那么,什么问题呢? How to fix it? 如何解决? Many thanks! 非常感谢!


请试试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM