How can I get all values from a JSON
object and then display them to the Worksheet at once?
This is how my JSON
object looks:
{"report_suites": [
{
"rsid": "op-api-docs",
"site_title": "API Docs Portal"
},
{
"rsid": "op-bigideas",
"site_title": "Big Ideas"
},
{
"rsid": "op-education",
"site_title": "Education"
},
{
"rsid": "op-education-dev",
"site_title": "Education - Dev"
},
{
"rsid": "op-global",
"site_title": "Global"
},
{
"rsid": "op-global-dev",
"site_title": "Global - Dev"
}
]}
This is how I tried to get this done, but it returns the following error:
The best overloaded method match for 'System.Collections.Generic.List.AddRange(System.Collections.Generic.IEnumerable)' has some invalid arguments
dynamic response = JsonConvert.DeserializeObject(responseXml);
var just_rs = response.report_suites;
var report_title = new List<string>();
var report_id = new List<int>();
foreach(var item in just_rs) {
report_title.AddRange(item.site_title);
report_id.AddRange(item.rsid);
}
rng = (Excel.Range)ws.Range[ws.Cells[2, 1], ws.Cells[report_id.Length, 1]];
rng.Value = report_id;
rng = (Excel.Range)ws.Range[ws.Cells[2, 2], ws.Cells[report_title.Length, 2]];
rng.Value = report_title;
Where response
is my JSON
object mentioned above.
If I use Add
instead of AddRange
I get the following error:
The best overloaded method match for 'System.Collections.Generic.List.Add(string)' has some invalid arguments