Hey all I am looking at the following json string I Serialize using SerializeObject in Json.net:
{
"ServTypeList": [
{
"id": 1,
"name": "COMPUTER"
},
{
"id": 2,
"name": "MONITOR"
},
{
"id": 3,
"name": "NETWORK COMPONENTS"
},
{
"id": 4,
"name": "OFFICE EQUIPMENT"
},
{
"id": 5,
"name": "SOFTWARE"
},
{
"id": 6,
"name": "STORAGE"
}
],
"ServTypeList1": [
{
"CurrentVersion": "Jun 23 2017 (0 days ago)",
"theQuery": "SELECT id,name\tFROM servType"
}
]
}
And this is my C# code in order to format it like above:
string json = JsonConvert.SerializeObject(_ServTypeList, Formatting.Indented);
The _ServTypeList is in a DataSet format which has a name of ServTypeList.
So now I am wanting to take out the TypeList and just get teh array of data from the json string.
So I tried something like this:
var trying = json["TypeList"];
But that gives me an error of
Error CS1503 Argument 1: cannot convert from 'string' to 'int'
So I'm not sure why its trying to cast it as an int?
How do I just get this information:
[{
"id": 1,
"name": "COMPUTER"
},
{
"id": 2,
"name": "MONITOR"
},
{
"id": 3,
"name": "NETWORK COMPONENTS"
},
{
"id": 4,
"name": "OFFICE EQUIPMENT"
},
{
"id": 5,
"name": "SOFTWARE"
},
{
"id": 6,
"name": "STORAGE"
}]
DataSet, just serialize the table you need, as suggested by @Elemental Pete:string json = JsonConvert.SerializeObject(_ServTypeList.Tables["ServTypeList"], Formatting.Indented);