Answer the question
In order to leave comments, you need to log in
How to get value from JSON array?
Hello. There is an array returned by one API, here it is: pastebin.com/7atf5CzT
I need to get each 'value' for each name (key), for example AK-47 | Aquamarine Revenge (Battle-Scarred) => 1420. I use newtonsoft.json library for parsing. I've already tried this and that, but it doesn't work. What's wrong?
dynamic decoded = JsonConvert.DeserializeObject(response.Body);
decoded = decoded.response;
foreach (dynamic item in decoded.items)
{
Console.WriteLine(item.value); // RuntimeBinderException: JProperty does not contain a definition for 'value'
Console.WriteLine(item[2]); // InvalidOperationException: cannot access child value on JProperty
Console.WriteLine(item.Name.ToString()); // работает отлично
}
Answer the question
In order to leave comments, you need to log in
dynamic obj = JsonConvert.DeserializeObject(json);
var resp = obj.response;
foreach (JProperty item in resp.items)
{
var token = item.FirstOrDefault();
if (token != null)
Console.WriteLine(token["value"]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question