How to convert Json String to Object with Dictionary using JayRock

做~自己de王妃 提交于 2019-12-11 09:50:55

问题


I want to convert a Json string to an Object in 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? How to fix it? Many thanks!


回答1:



Please try:

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


来源:https://stackoverflow.com/questions/10792007/how-to-convert-json-string-to-object-with-dictionary-using-jayrock

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!