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

 

posted @ 2022-12-13 23:04  ProZkb  阅读(1039)  评论(0编辑  收藏  举报