我有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