Deserialize JSON string to Dictionary

后端 未结 5 1721
长情又很酷
长情又很酷 2020-11-30 04:32

I have this string:

[{ \"processLevel\" : \"1\" , \"segments\" : [{ \"min\" : \"0\", \"max\" : \"600\" }] }]

I\'m deserializing the object:

5条回答
  •  醉梦人生
    2020-11-30 05:21

    I like this method:

    using Newtonsoft.Json.Linq;
    //jsonString is your JSON-formatted string
    JObject jsonObj = JObject.Parse(jsonString);
    Dictionary dictObj = jsonObj.ToObject>();
    

    You can now access anything you want using the dictObj as a dictionary. You can also use Dictionary if you prefer to get the values as strings.

提交回复
热议问题