我創建了一個字典,你可以看到:初始化在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);
}
}
}
但運行我的代碼時,上述功能正試圖把自己的數據放入我的字典裏。我的應用程序將返回該錯誤後: