C# 将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.Value);//升序
    //keyValues.OrderByDescending(m => m.Key);//降序
    return JsonConvert.SerializeObject(keyValues);
}
//把Json字符串转换成Dictionary对象
    var objJson = JsonConvert.DeserializeObject<Dictionary<string, object>>(paramJson);
    //签名字符串
    string sign = secrectKey;
    foreach (var temp in objJson)
    {
        sign += temp.Key + temp.Value;
    }

 

posted @ 2020-07-05 10:50  netlock  阅读(692)  评论(0编辑  收藏  举报