编程语言
首页 > 编程语言> > c# json object Dictionary互转

c# json object Dictionary互转

作者:互联网

            //object 转 string(json)
            string result = JsonConvert.SerializeObject(user);
            //object 转 JObject
            JObject jo = (JObject)JToken.FromObject(user);
            //JObject 转 string(json 带换行)
            //jo.ToString()
            //object 转 Dictionary
            IDictionary<string, object> list = ObjectToDictionaryHelper.ToDictionary(user);
            //string(json) 转 Dictionary
            Dictionary<string, Object> list2 = JsonConvert.DeserializeObject<Dictionary<string, Object>>(result);
            //string(json) 转 object
            User user3 = JsonConvert.DeserializeObject<User>(result);

 

标签:string,Dictionary,c#,object,JObject,json,result,互转
来源: https://www.cnblogs.com/Violety/p/14958613.html