Ich deserialisiere einen JSON-String in ein Wörterbuch in C#, aber ich möchte das Wörterbuch nach einem Wert sortieren, um es auf einer Tabelle mit hohen Punktzahlen anzuzeigen. Das Wörterbuch kehrt jetzt in fester Reihenfolge zurück.Sortierwörterbuch nach Wert C#
var temp = Json.Deserialize(www.text) as Dictionary<string,object>;
if (temp != null)
{
data = (List<object>)temp["_items"];
}
JSON String
"_items":[
{
"_updated":"Thu, 01 Jan 1970 00:00:00 GMT",
"_id":"-",
"Name":"John Doe",
"_links":{
"self":{
"href":"Players/-",
"title":"Player"
}
},
"_created":"Thu, 01 Jan 1970 00:00:00 GMT",
"FacebookId":XXXXX,
"HighScore":8862,
"_etag":"-"
},
{
"_updated":"Thu, 01 Jan 1970 00:00:00 GMT",
"_id":"-",
"Name":"John Smith",
"_links":{
"self":{
"href":"Players/-",
"title":"Player"
}
},
"_created":"Thu, 01 Jan 1970 00:00:00 GMT",
"FacebookId":XXXXXX,
"HighScore":32000,
"_etag":"-"
}
],
Zell Creation
var dict = (Dictionary<string, object>) data[row];
// Set Name
cell.nameText.text = dict["Name"].ToString();
// Set score
cell.score.text = string.Format("{0:n0}", dict["HighScore"]);
// Fb Profile IMG
StartCoroutine(getFBPicture(cell.image, dict["FacebookId"].ToString()));
Ich empfehle, mit LINQ: https://stackoverflow.com/questions/5949904/c-sharp-sort-dictionary-with-linq – MessLuke
Mögliche Duplikat [Wie Sie ein Wörterbuch nach Wert sortieren Sie?] (Https://stackoverflow.com/questions/289/how-do-you-sort-a-dictionary-by-value) – FortyTwo
@ISHIDA durch die HighScore-Variable in der JSON – Prad