I have a JSON that I receive which has dynamic numeric object names. I´m not sure how to convert this into a model.
I have tried to create a model structure but I did not manage to solve it.
My JSON looks like this:
{
"data_positions": {
"695243": { <- this is a dynamic number which can be different for another request
"id": "695243",
"name": "Gothenburg",
"numberOfPos": "59865",
"partners": {
"9658265": {
"id": "9658265",
"partner": {
"id": "1",
"name": "FirstOne"
}
},
"2365895": { <- this is a dynamic number which can be different for another request
"id": "2365895",
"participant": {
"id": "2",
"name": "SecondOne",
}
},
"1478563": { <- this is a dynamic number which can be different for another request
"id": "1478563",
"participant": {
"id": "3",
"name": "ThirdOne"
}
}
}
}
}
}
And the model I have created looks like this:
public class Data
{
[JsonProperty("data_positions")]
public DataPositions DataPositions { get; set; }
}
public class Data
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("numberOfPos")]
public int NumberOfPos { get; set; }
[JsonProperty("partners")]
public Partner[] Partners { get; set; }
}
public class Partner
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("numberOfPos")]
public int NumberOfPos { get; set; }
}
So what I´m unsure of is how to fetch the data from the object 695243
under data_positions
and 2365895
, 1478563
in partners
.
The expected result is a model that can fetch the data from the JSON provided above.
Appreciate all help.