I'm trying to GROUP the JSON by BOARD and SUM the likes_count, but not sure how to approach this, since I can only access the Transaction class by looping through Root first?
public class Transaction
{
public string Post { get; set; }
public int board {get; set; }
public int Sent_from { get; set; }
public int likes_count { get; set; }
}
public class Root
{
public int Sent_to { get; set; }
public List<Transaction> Transactions { get; set; }
}
static async System.Threading.Tasks.Task Main(string[] args)
{
var json = "";
using (WebClient wc = new WebClient())
{
json = wc.DownloadString("xxxxxxx");
}
var obj = JsonConvert.DeserializeObject<List<Root>>(json);
foreach (var item in obj)
{
foreach (var child in item.Transactions)
{
// access sent_from, likes_count and post.
}
}
}
I would've normally used:
obj.GroupBy(t => t.post);
Here is a JSON Sample:
Sent_to: X,
total_received_likes: X,
Transactions: [
{
Post: "50776785",
board: "600",
Sent_from: 359716,
likes_count: 4,
},
{
Post: "5085129785",
board: "500",
Sent_from: 359716,
likes_count: 6,
},
{
Post: "506542785",
board: "500",
Sent_from: 359716,
likes_count: 9,
},
The expected output in this case:
15 likes in board 500
4 likes in board 600.