Lima1337 Lima1337 - 6 months ago 38
JSON Question

C# JSON Get specific attribute with multiple roots

So basically, I am building a C# application that will retrieve specific values from a URL. The URL is
URL to Scrape

The attributes that I need to grab are: 'id', 'size', 'inStock' and 'ATS' from each different size of product.


I have tried the code from this URL but no luck.

string data = client.DownloadString(region).Replace("\n", "").Replace("\r", "").Replace(@"\", "").Replace("\t", "");
dynamic dynObj = JsonConvert.DeserializeObject(data);
var someVar1 = dynObj["variants"]["BY1910_530"][1]["id"].ToString();

Answer Source

Please try something like this (As you are using JsonConvert, I assume you've already got the Newtonsoft.Json Nuget package):

var client = new HttpClient();
string json = await client.GetStringAsync(@"");
var jobj = JObject.Parse(json);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download