日期:2014-05-17  浏览次数:20465 次

给定关键字不在字典中?
用C#网页 做手机支付宝功能,用RSA签名
结果  支付宝接口 接入的时候出错

SortedDictionary<string, string> sd = new SortedDictionary<string, string>();
        int count = 0;
        string sparam = "";
        string key = "";
        string value = "";
        for (int i = 0; i < result.Length; i++)
        {
            sparam = result[i];
            count = sparam.IndexOf('=');
            key = sparam.Substring(0, count);
            value = sparam.Substring(count + 1, sparam.Length - (count + 1));
            sd.Add(key, value);
        }
       //  出错  给定关键字不在字典中?
        string sign = sd["sign"];

        //配置待签名数据
        Dictionary<string, string> dicData = MobileFunction.FilterPara(sd);
        string req_Data = MobileFunction.CreateLinkString(dicData);

有人知道为什么

------解决方案--------------------
那就是 sd 字典中没有 key为sign 的咯

------解决方案--------------------
count = sparam.IndexOf('=');==>count = sparam.IndexOf('=') - 1;  
或者
key = sparam.Substring(0, count); ==>key = sparam.Substring(0, count-1); 
------解决方案--------------------
请求数据参数和网址返回数据是两回事. 也许请求返回结果中并不包含那个属性