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);

 

posted @ 2021-07-01 14:28  violety  阅读(1325)  评论(0编辑  收藏  举报