I have this JSON string:
{
"countries": [
{
"countryCode": "AR",
"country": "Argentina"
},
{
"countryCode": "BR",
"country": "Brazil"
}
]
}
and this Country class and countries list:
List<Country> countries { get; set; }
class Country
{
public string country { get; set; }
public string countryCode { get; set; }
}
I need to create a two-dimensional object array containing the countries code and name:
propVal[0, 0] = "AR";
propVal[0, 1] = "Argentina";
propVal[1, 0] = "BR";
propVal[1, 1] = "Brazil";
.
.
.
Right now I'm "manually" looping through the countries list and build the object array:
int row = 0;
foreach (Country country in countries)
{
propVal[row, 0] = country.countryCode;
propVal[row, 1] = country.country;
row++;
}
The long shot is to have a generic way, applicable to other JSONs, having let's say 3 or more properties and resulting in a x-dimensional object array.
Is there a LINQ way to do this? I know about this thread, dealing with one object property and for which the LINQ approach is countries.Select(x=>x.country).ToArray()
, but in my case there are multiple properties needed.
Thank you for your help!