问题
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