C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,208 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
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; }
}