小编The*_*aik的帖子

如何按值对 JObject 进行排序

我有一些 JSON:

{
    "AI": "1",
    "AJ": "0",
    "AM": "0",
    "AN": "0",
    "BK": "5",
    "BL": "8",
    "BM": "0",
    "BN": "0",
    "BO": "4",
    "CJ": "0",
    "CK": "2"
}
Run Code Online (Sandbox Code Playgroud)

我想按数字从高到低排序,并通过编写 JSON 的第一个索引来获取数字最高的属性。你能帮助我吗?

这是我到目前为止:

string voteJson = File.ReadAllText("vote.json");
Object voteObj = JObject.Parse(voteJson);

//How to sort the object here?

//Saving it 
string output = Newtonsoft.Json.JsonConvert.SerializeObject(voteObj, 
    Newtonsoft.Json.Formatting.Indented);
File.WriteAllText("vote-sorted.json", output);
Run Code Online (Sandbox Code Playgroud)

c# sorting json json.net

6
推荐指数
1
解决办法
5454
查看次数

标签 统计

c# ×1

json ×1

json.net ×1

sorting ×1