public static 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进行排序 var OrderBy = keyValues.OrderByDescending(m => m.Key);//降序 var dicRet = OrderBy.ToDictionary(X => X.Key, X => X.Value); return JsonConvert.SerializeObject(dicRet); }
Dictionary<string, object> pairs = new Dictionary<string, object>() { { "bookId",2}, { "virtualQuantity","10"} }; var json = Newtonsoft.Json.JsonConvert.SerializeObject(pairs); List<string> vs = new List<string>(); vs.Add("aqsMyu8x"); vs.Add("123AK"); vs.Add("123456"); vs.Add("1653721579"); vs.Add(json); vs.Sort(StringComparer.Ordinal);//https://www.codenong.com/28638714/ string strJoin = string.Join(string.Empty, vs); var strEncode = HttpUtility.UrlEncode(strJoin); var strReplce = strEncode.Replace("+", "%20");
标签:string,json,Add,JSON,vs,Key,var,排序,进行 From: https://www.cnblogs.com/ZkbFighting/p/16980938.html