{ "check":"success", "stats":{ "2":{ "rank":1, "score":"2000", "name":"Muhammad" }, "3":{ "rank":1, "score":"2000", "name":"Ramsay" }}}
this is my json string. I want to use "stats" as a list to check how many entries it has. Then I need to get the rank, name, score etc from each entry. My code is,
var result = Json.Deserialize(jsontest) as Dictionary<string,object>;
object st;
var rankholders = new List<object>();
if (result.TryGetValue("stats", out st))
{
rankholders = (List<object>)(((Dictionary<string, object>)st)["stats"]);
foreach (object obj in rankholders)
{
var tempDict = ((Dictionary<string,object>)(rankholders[0]));
WeeklyStatsItem tempRow = new WeeklyStatsItem ();
tempRow.rank = (string)tempDict["rank"];
tempRow.name = (string)tempDict["name"];
tempRow.score = (string)tempDict["score"];
weeklyScoreList.Add (tempRow);
}
}
But I get keynotfound exception. Any idea how to parse such a json loop?