'Parsing JSON Visual Studio C# vs VB
I'm having problems parsing some JSon (from an HttpRequest. The received string is :
{{
"@odata.context": "https://xxx/$metadata#customers(id,name,nbuys,domestic)",
"value": [
{
"@odata.etag": "W/\"186553045\"",
"id": "bb1d4f0b",
"name": "John Smith",
"nbuys": 5,
"domestic": true
},
{
"@odata.etag": "W/\"186553045\"",
"id": "bgjf4f0a",
"name": "Jane Doe",
"nbuys": 8,
"domestic": false
}
]
}}
I successfully deserialize the string in C# using NewtonSoft:
var J = JsonConvert.DeserializeObject( jsonstring);
then I can iterate through each customer
For Each (item in J.value.Children())
{
console.WriteLine(item.name);
}
This works fine, but I need to do the same in Visual Basic. I get the same deserialized object:
Dim J as JObject = JsonConvert.DeserializeObject( jsonstring)
but I can't get the following to work
Foreach item In J.value.Children()
console.WriteLine(item.name);
next
This doesn't work. I've tried using various J objects without any luck. The only thing I've been able to get is
dim i as integer = J.Count
What am I doing wrong? Thanks for helping
Solution 1:[1]
The equivalent in VB would be
Dim J = JsonConvert.DeserializeObject(jsonstring)
For Each item In J("value").Children()
Console.WriteLine(item.name)
next
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 | Anu6is |
