我创建了一个字典,你可以看到:初始化在C#中返回溢出错误字典
public Dictionary<string, string> TipList
{
get { return TipList; }
set { TipList = value; }
}
我取从服务的一些数据,我希望把这些数据转化为我的字典里,你可以在这里看到:
Dictionary<string, string> dict = new Dictionary<string, string>();
try
{
using (var response = (HttpWebResponse)request.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
var objText = reader.ReadToEnd();
var list = JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(objText).ToDictionary(x => x.Keys, x => x.Values);
object o;
object o1;
foreach (var item in list)
{
o = item.Value.ElementAt(0);
o1 = item.Value.ElementAt(1);
dict.Add(o.ToString(), o1.ToString());
}
GlobalVariable.TipListCache.Add(NewCarReceiption.CSystem.Value, dict);
NewCarReceiption.TipList = dict.Where(i=>i.Key!=null & i.Value!=null).ToDictionary(x => x.Key, x => x.Value);
}
}
}
但运行我的代码时,上述功能正试图把自己的数据放入我的字典里。我的应用程序将返回该错误后: