Reputation: 2150
I have a json object like this
{
"UrbanSourceUnsealedRoad":
[
{
"Name": "Baseflow Total Nitrogen Standard Deviation (log mg/L)",
"Min": "1",
"Max": "2",
"Default": "3",
"AlwaysInReport": "FALSE",
"Flag": "YES"
},
{
"Name": "Stormflow Total Nitrogen Mean (log mg/L)",
"Min": "4",
"Max": "5",
"Default": "6",
"AlwaysInReport": "FALSE",
"Flag": "YES"
},
...
],
"UrbanSourceSealedRoad":
[
{
"Name": "Baseflow Total Nitrogen Standard Deviation (log mg/L)",
"Min": "1",
"Max": "2",
"Default": "3",
"AlwaysInReport": "FALSE",
"Flag": "YES"
},
{
"Name": "Stormflow Total Nitrogen Mean (log mg/L)",
"Min": "4",
"Max": "5",
"Default": "6",
"AlwaysInReport": "FALSE",
"Flag": "YES"
},
...
],
...
}
I have deserialised this using JSON.net
in C#
JsonConvert.DeserializeObject<Dictionary<string, List<ParameterInfo>>>(json)
This works fine, however now I would like to change the json so that it contains an extra field at the top of the file.
ie:
{
"UrbanLandUse" : ["UrbanSourceMixed", "UrbanSourceSealedRoad", "UrbanSourceUnsealedRoad" ],
"UrbanSourceUnsealedRoad":
[
{
...
But now my json file is no longer a dictionary containing List<ParameterInfo>
The JSON Spec seems to indicate that it is indeed possible
But I'm not sure how to deserialize it with the JSON.net API
Can I do this?
Upvotes: 0
Views: 733
Reputation: 651
Prepare a containing object which contains ParameterInfo and the new one you want. Something like this:
public class Container
{
public Dictionary<string, List<ParameterInfo>> {get; set;}
public string[] UrbanLandUse {get; set;}
}
Then deserialize into that object like this:
JsonConvert.DeserializeObject<Container>(json);
Let me know if this works.
Upvotes: 1