https://www.cgjoy.com/thread-106639-1-1.html

1.新建字典,添加元素
  dictionary<string,string>dic=newdictionary<string,string>();
2.判断目标元素是否已存在

  If(dic.ContainsKey(查询主键的内容,内容要唯一)==false){
       Dic.Add(string,string);
  }
3.轮询字典
  String temp=””;
  Foreach(KeyValuePair<string,string>kvp in dic){
       Temp=temp+kvp.Key+”,”+kvp.Value+”\n”;
  }
4.删除或清空字典  dic.Clear();
 

public class HttpMsgMc
{
public string Url;
public Dictionary<string, string> ParamsDic;
public int UIEventCode;

public void Change(string url, Dictionary<string, string> paramDic, int uiEventCode)
{
this.Url = url;
this.UIEventCode = uiEventCode;
this.ParamsDic = paramDic;
}
}

class HttpManager类 HttpMsgMc requestMc = message as HttpMsgMc;// ----- 组装表单数据 start -----
        WWWForm formData = new WWWForm();
        if (requestMc.ParamsDic.ContainsKey("device") == false)
        {
            requestMc.ParamsDic.Add("device", "app");
        }
        // 添加 用户的 guid
        if (requestMc.Url != URL_MC.Login && requestMc.Url != URL_MC.Register)
            if (requestMc.ParamsDic.ContainsKey("guid") == false)
                requestMc.ParamsDic.Add("guid", Player.Instance.Guid ?? "");

        UtilMc.CalculateSign(requestMc.ParamsDic, out string sign);

        formData.AddField("sign", sign);
        UnityEngine.Debug.Log("");
        UnityEngine.Debug.Log("[http]====================== request ==========================");
        UnityEngine.Debug.Log("[http] 发送请求: url: " + requestMc.Url);
        foreach (KeyValuePair<string, string> item in requestMc.ParamsDic)
        {
            formData.AddField(item.Key, item.Value);
            UnityEngine.Debug.Log("\tformData: " + item.Key + " : " + item.Value);
        }
        UnityEngine.Debug.Log("");
        // ----- 组装表单数据 end -----
 
05-01 07:29