void Main()
{
const string thatJsonYouWrote = @"[{""Id"":100, ""Name"":""Rush"", ""Category"":""Prog""}, {""Id"":200, ""Name"":""Led Zeppellin"", ""Category"":""Rock""}, {""Id"":300, ""Name"":""Grumpy Lettuce"", ""Category"":""Weird""}]";
IDictionary<int,string> thatThingYouWanted = ParseJsonExample(thatJsonYouWrote);
}
IDictionary<int,string> ParseJsonExample(string json)
{
object[] items = ((object[])new JavaScriptSerializer().DeserializeObject(json));
return items
.Cast<Dictionary<string,object>>()
.ToDictionary(_ => Convert.ToInt32(_["Id"]), _ => _["Name"].ToString());
}
注:名前空間を参照System.Web.Extensions.dll
してインポートする必要がありますSystem.Web.Script.Serialization