question

AlphaBeta-8233 avatar image
0 Votes"
AlphaBeta-8233 asked AlphaBeta-8233 edited

Json Parsing in c#(Console application)

I need to parse Json into C# (Console Application) and also need to view the parsed data in a table format.

Json Code:

 {
   "RLC": [
     {
       "PAR": ""
     },
     {
       "PAR": ""
     },
     {
       "PAR": ""
     }
   ],
   "PR":

Please help out.


dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
0 Votes"
Castorix31 answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AgaveJoe avatar image
0 Votes"
AgaveJoe answered AgaveJoe edited

You did not mention the target framework or share the expected table layout.

Below is a .NET 5 example where the JSON data is stored in a file.

     class Program
     {
    
         static void Main(string[] args)
         {
             string json = File.ReadAllText(@"C:/temp/json.txt");
             Rootobject root = JsonSerializer.Deserialize<Rootobject>(json);
    
             Console.WriteLine(root.PNRAmount.AuthorizedBalanceDue);
    
             foreach(var item in root.RecordLocator)
             {
                 Console.WriteLine($"\t{item.PNR}");
             }  
         }
     }
     public class Rootobject
     {
         public Recordlocator[] RecordLocator { get; set; }
         public Pnramount PNRAmount { get; set; }
     }
    
     public class Pnramount
     {
         public string BalanceDue { get; set; }
         public string AuthorizedBalanceDue { get; set; }
         public string SegmentCount { get; set; }
         public string PassiveSegmentCount { get; set; }
         public string TotalCost { get; set; }
         public string PointsBalanceDue { get; set; }
         public string TotalPointCost { get; set; }
         public object[] AlternateCurrencyCode { get; set; }
         public string AlternateCurrencyBalanceDue { get; set; }
     }
    
     public class Recordlocator
     {
         public string PNR { get; set; }
     }


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.