UrlEncode 会把对象的大写转成小写

 

 

Dictionary<string, object> pairs = new Dictionary<string, object>()
{
    { "bookId",2},
    { "virtualQuantity","10"}
};

var json = Newtonsoft.Json.JsonConvert.SerializeObject(pairs);

var sd = StortJson(json);
List<string> vs = new List<string>();
vs.Add("aqsMyu8x");
vs.Add("123AK");
vs.Add("123456");
vs.Add("1653721579");
vs.Add(sd);
vs.Sort(StringComparer.Ordinal);
//join
string strJoin = string.Join(string.Empty, vs);
//UrlEncode
var strEncode = HttpUtility.UrlEncode(strJoin);

//UrlEncode 会把对象的大写转成小写...

文档:123456123AK1653721579aqsMyu8x{"virtualQuantity":"10","bookId":2}
代码:123456123AK1653721579aqsMyu8x{"virtualQuantity":"10","bookId":2}


strEncode:123456123AK1653721579aqsMyu8x%7b%22virtualQuantity%22%3a%2210%22%2c%22bookId%22%3a2%7d

文档:     123456123AK1653721579aqsMyu8x%7B%22virtualQuantity%22%3A%2210%22%2C%22bookId%22%3A2%7D


UrlEncode这个方法要重写一下:
public static string UrlEncode(string str)
{
    str = HttpUtility.UrlEncode(str);
    byte[] buf = Encoding.ASCII.GetBytes(str);
    for (int i = 0; i < buf.Length; i++)
    {
        if (buf[i] == '%')
        {
            if (buf[i + 1] >= 'a') buf[i + 1] -= 32;
            if (buf[i + 2] >= 'a') buf[i + 2] -= 32;
            i += 2;
        }
    }
    return Encoding.ASCII.GetString(buf);
}

 

posted @ 2022-12-14 10:20  ProZkb  阅读(100)  评论(0编辑  收藏  举报