无网不进  
软硬件开发

c# 对JSON字符串排序(KEY/VALUE)

需要添加的引用:

using System.Collections.Generic;

using System.Linq;

using Newtonsoft.Json;

1 public string StortJson(string json)
2 {
3       var dic = JsonConvert.DeserializeObject<SortedDictionary<string, object>>(json);
4       SortedDictionary<string, object> keyValues = new SortedDictionary<string, object>(dic);
5       keyValues.OrderBy(m => m.Key);//升序 把Key换成Value 就是对Value进行排序
6       //keyValues.OrderByDescending(m => m.Key);//降序
7       return JsonConvert.SerializeObject(keyValues);
8 }

 

posted on 2019-01-26 10:47  无网不进  阅读(1646)  评论(0编辑  收藏  举报