Deserializing a List of Objects that contain a Dictionary

后端 未结 3 547
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 09:06

I\'ve seen a lot of examples that seem to indicate that what I\'m doing should work, but for whatever reason, it doesn\'t. I\'m trying to deserialize a collection of objects

3条回答
  •  一个人的身影
    2021-01-18 09:45

    Yeah true, the deserializers dont deserialize the dictornary object especailly if you have any complex types and dates. The solution for that is use Newtonsoft.Json use Jobject to deserialize you can take this as an example and try.. In your case you can take this to var or Jobject

        JArray resources=(JArray)JsonConvert.DeserializeObject(objJson);
                         itemStores = resources.Select(resource => new Resource`enter code here`
                         {
                             SpaceUsed = long.Parse(resource["indexDiskMB"].ToString()),
                             ItemId =resource["id"].ToString(),
                             CountItems =Int32.Parse(resource["numItems"].ToString()),
                             ItemType=resource["type"].ToString()
    
                         }).ToList();
    

提交回复
热议问题