我有Dictionary包含字符串作爲鍵和System.Object作爲值。添加到詞典不添加
Dictionary<string, System.Object> test = new Dictionary<string, System.Object>();
我創建並添加值
Debug.Log("Key:" + (string)KEY.obj);
Debug.Log("VALUE:" + (string)VALUE.obj);
test.Add((string)KEY.obj, VALUE.obj);
if (test.ContainsKey("id")){
Debug.Log("contains!");
}
else{
Debug.Log("does not contain!");
}
調試控制檯
鍵和值是類的一個對象
private sealed class ResolveValue {
public readonly System.Object obj;
public readonly int end;
public ResolveValue(System.Object obj, int end){
this.obj = obj;
this.end = end;
}
}
其中KEY是「id」,VALUE是「myData」。
花了我相當長的一段時間才發現問題。 這怎麼可能?
信息
所有字符串從字節轉換器。 這是我做的調試。
Debug.Log("--------");
string msg = "";
foreach(byte b in bytes){
msg += b + " ";
}
Debug.Log(msg);
Debug.Log("--------");
string message = System.Text.Encoding.UTF8.GetString(bytes);
Debug.Log(message);
ResolveValue response = new ResolveValue(message, end);
可變年底是一個整數,無關這個問題。
有沒有 '身份證' 後的空間? – zmbq 2015-03-30 19:22:30
請提供一個完整的示例。 – 2015-03-30 19:26:29
更改你的if語句爲:if(test.ContainsKey((string)KEY.obj)),所以我們可以肯定。 – 2015-03-30 19:26:32