大文字と小文字を区別しない新しい辞書を作成し、現在の辞書を入力するだけです。
var jsonObject = serializer.DeserializeObject(line) as Dictionary<string, object>;
var caseInsensitiveDictionary = new Dictionary<string, object>(jsonObject, StringComparer.OrdinalIgnoreCase);
[更新]テストコード:
Stopwatch stop1 = new Stopwatch();
Stopwatch stop2 = new Stopwatch();
//do test 100 000 times
for (int j = 0; j < 100000; j++)
{
//generate fake data
//object with 50 properties
StringBuilder json = new StringBuilder();
json.Append('{');
for (int i = 0; i < 100; i++)
{
json.Append(String.Format("prop{0}:'val{0}',", i));
}
json.Length = json.Length - 1;
json.Append('}');
var line = json.ToString();
stop1.Start();
var serializer = new JavaScriptSerializer();
var jsonObject = serializer.DeserializeObject(line) as Dictionary<string, object>;
stop1.Stop();
stop2.Start();
var caseInsensitiveDictionary = new Dictionary<string, object>(jsonObject, StringComparer.OrdinalIgnoreCase);
stop2.Stop();
}
Console.WriteLine(stop1.Elapsed);
Console.WriteLine(stop2.Elapsed);
Console.Read();
結果は次のとおりです。
デシリアライズ時間:1分21秒
辞書作成時間:3秒
したがって、主な問題は逆シリアル化です。辞書の作成は約4%です