Reputation: 13
Using the example code works correctly to get the non-nested data from "issues", how can I get the nested data from "issues"? In the picture you can see which data we are talking about.
Code:
try
{
var dynObj = JsonConvert.DeserializeObject<dynamic>(strResponseValue);
string records = dynObj["issues"].ToString();
JArray a = JArray.Parse(records);
List<string> colNames = new List<string>() {"expand", "key", "id",
"self" };
string headerRow = "";
foreach (string colName in colNames)
{
headerRow += "\"" + colName + "\";";
}
headerRow = headerRow.TrimEnd(';');
headerRow += "\n";
string dataRows = "";
foreach (var record in a)
{
string thisRecord = "";
foreach (string colName in colNames)
{
thisRecord += "\"" + record[colName] + "\";";
}
thisRecord = thisRecord.TrimEnd(';');
thisRecord += "\n";
dataRows += thisRecord;
}
csvData = headerRow + dataRows;
Console.WriteLine("\ncsvData:");
Console.WriteLine(csvData);
}
catch (Exception ex)
{
Console.WriteLine("Exeption Error" + ex.ToString());
}
Upvotes: 1
Views: 51
Reputation: 3902
If the json
is complex, you can let visual studio do the job.
For instance deserialize to MyClass
(from .Net Fundumentals - JSON Serialize/Deserialize):
MyClass? myclass = JsonSerializer.Deserialize<MyClass>(jsonString);
Upvotes: 1