需要添加的引用: using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; ...
public string StortJson(string json) { var dic = JsonConvert.DeserializeObject<SortedDictionary<string, object>>(json); SortedDictionary<string, object> keyValues = new SortedDictionary<string, object>(dic); keyValues.OrderBy(m => m.Key);//升序 把Key換成Value 就是對Value進行排序 //keyValues.OrderByDescending(m => m.Key);//降序 return JsonConvert.SerializeObject(keyValues); }
需要添加的引用:
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;