[Solved] Sort a string so I can use it with LINQ


If you are going to be dealing with these objects often then I would definitely make classes to represent them to make it easier to deserialize the JSON strings. If not then you can just roll something quick and dirty. Either way I think you are going to want to use the Json.NET library; it will make your life easier. Install it in your project by running this command in the package manager console:

Install-Package Newtonsoft.Json

For the quick and dirty solution, given a string called json, you can do this:

Newtonsoft.Json.Linq           // Namespace
.JArray                        // Class
.Parse(json)                   // Static method to parse string into a JArray
.Select(x => new               // Select anonymous types
{
    UserId = x["UserID"],
    Username = x["username"],
    GroupId = x["GroupID"],
    GroupName = x["GroupName"],
    Money = x["Money"],
})
.GroupBy(x => x.UserId)        // Group by user id.
.ContinueWithRemainingQuery();

solved Sort a string so I can use it with LINQ