How to convert Json String to Object with Dictionary using JayRock

1.8k Views Asked by At

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

There are 1 best solutions below

2
On


Please try:

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