'What c# model will serialize to a JSON object with dynamic property names each having a list of lists of values?
What data structure/collection in C# that when I serialize using Newtonsoft.Json would give me a result like this, where the property names "data_point1" are dynamic and defined at runtime?
{
"data": {
"data_point1": [
[
string,
string
],
[
string,
string
]
],
"data_point2": [
[
string,
string
],
[
string,
string
]
],
}
}
I tried with List of Dictionaries and it gave result like below:
{
[
{
"data_point1": [
[
string,
string
]
],
"data_point2": [
[
string,
string
]
]
}
]
}
Edit1: changed "Property" to "data_point" as it was confusing. Dataset "data" has thousands of data points, each data point is a collection of data at a specific time.
Edit2: for anyone who this this not real Json, this is from an instruction of a 3rd party API I have to push data to
{
"userToken": "XXXX-XXXX-XXXX-XXXX",
"sessionToken": "XXXX-XXXX-XXXX-XXXX",
"tvqs":
{
"tag1": [ [ "2018-01-09T12:00:00.0000000-05:00", "value" ] ],
"tag2": [
[ "2018-01-09T11:59:55.0000000-05:00", "value" ] ,
[ "2018-01-09T12:00:00.0000000-05:00", "value" ]
]
}
}
Solution 1:[1]
This can be done as a dictionary with two nested lists inside.
{
//Dictionary
"data": {
// Dictionary Key with value List<List<string>>
"Property1": [
//Entry in List<List<string>>
[
//Entry in List<string>
string,
string
],
[
string,
string
]
],
}
}
using System.Collections.Generic;
var data = new Dictionary<string, List<List<string>>>();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sebastian Börgers |
