我正在使用Visual Studio / Xamarin开发一个Android应用程序我必须对包含JSON
对象的字符串进行排序,如下所示:
[{"Entities":{"en-US":{"Items":[{"Resources":[], "Id":"1234567","Name":"Filter","ContentBody":"","Cover":"","Language":,"Action":0}],"Id":"1234567","Name":"04 SOMETHING","ContentBody":"","Cover":"","Language":"en-US","Action":0},"it-IT":{"Items":[{"Resources":[], "Id":"1234567","Name":"Filtro","ContentBody":"","Cover":"","Language":null,"Action":0}]
这是我的json的一小部分,我需要按名称排序JSON(“04 SOMETHING”)这个“名称”由数字ID和字符串组成(我需要按此id排序)。
我怎么能这样做?
答案 0 :(得分:0)
您可以使用此代码:
JArray sorted = new JArray(jsonResult["Items"].OrderBy(obj => obj["Id"]));
jsonResult["Items"] = sorted;