c# - How to sort a Newtonsoft JArray? -


would possible sort jarray below col2 example?

[     {         "col1": "thiscol",         "col2": "thisval"     },     {         "col1": "thiscol2",         "col2": "thisval2"     },     {         "col1": "thiscol3",         "col2": "thisval3"     } ] 

if converting array solution how this?

i don't think can sort jarray in place, can sort contents , load result jarray. work you?

string json = @" [     {         ""col1"": ""foo"",         ""col2"": ""bar""     },     {         ""col1"": ""baz"",         ""col2"": ""quux""     },     {         ""col1"": ""fizz"",         ""col2"": ""bang""     } ]";  jarray array = jarray.parse(json);  jarray sorted = new jarray(array.orderby(obj => obj["col2"]));  console.writeline(sorted.tostring(formatting.indented)); 

output:

[   {     "col1": "fizz",     "col2": "bang"   },   {     "col1": "foo",     "col2": "bar"   },   {     "col1": "baz",     "col2": "quux"   } ] 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -