bla

mail@pastecode.io avatar
unknown
csharp
15 days ago
2.1 kB
5
Indexable
Never
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

public class PrizeDistribution
{
    public string Id { get; set; }
    public string Name { get; set; }
    public List<PrizeStructureItem> PrizeStructureItems { get; set; }
}

public class PrizeStructureItem
{
    public string Id { get; set; }
    public int Ranking { get; set; }
    public string Range { get; set; }
    public string Percentage { get; set; }
}

public class Program
{
    public static void Main()
    {
        string jsonData = @"[
          {
            ""id"": ""fefa0da1-d80f-45fe-9ebc-d738482b8f53"",
            ""name"": ""prize_distribution_1 (2)"",
            ""prize_structure_items"": [
              {""id"": ""dd042d0e-3d72-4949-9554-ff0cb13a516f"", ""ranking"": 1, ""range"": ""3-10"", ""percentage"": ""70.0""},
              {""id"": ""3b44669c-b256-4eb1-953f-8b9048aff532"", ""ranking"": 2, ""range"": ""3-10"", ""percentage"": ""30.0""}
              // Add other items as per your actual data...
            ]
          }
        ]";

        var distributions = JsonConvert.DeserializeObject<List<PrizeDistribution>>(jsonData);
        var tableData = new Dictionary<string, List<string>>();

        foreach (var distribution in distributions)
        {
            foreach (var item in distribution.PrizeStructureItems)
            {
                if (!tableData.ContainsKey(item.Range))
                {
                    tableData[item.Range] = new List<string>();
                }
                // Ensure the list is correctly sized
                while (tableData[item.Range].Count < item.Ranking)
                {
                    tableData[item.Range].Add(null);
                }
                tableData[item.Range][item.Ranking - 1] = item.Percentage;
            }
        }

        // Output or use the tableData as needed
        foreach (var range in tableData)
        {
            Console.WriteLine($"Range: {range.Key}");
            foreach (var percentage in range.Value)
            {
                Console.WriteLine($"  {percentage}");
            }
        }
    }
}
Leave a Comment