对JSON里的字段进行排序
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");
人各有命,上天注定,有人天生为王,有人落草为寇。脚下的路,如果不是你自己的选择,那么旅程的终点在哪,也没人知道。你会走到哪,会遇到谁,都不一定。