WebClient client = new WebClient();
Stream stream = client.OpenRead(" some link ");
StreamReader reader = new StreamReader(stream);
Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(reader.ReadLine());
List<String> list = new List<string>();
//loading list
for (int i = 0; i < ((string)jObject["some_stream"][i]["some_channel"]["some_name"]).Count(); i++)
{
string result = ((string)jObject["some_streams"][i]["some_channel"]["some_name"]);
list.Insert(i, result);
}
stream.Close();
This code is working, but in json data I have 20+ results should be returned, but I only get 8.
What could be the cause?
you are counting the length of a string. at some point the length of that string is equal to or less than i (the 9th value of the string if you manage to iterate 8 times)
That is this piece of code
returns the length of a string at location
iso if you manage to iterate 8 times then the string at jObject[“some_stream”][9][“some_channel”][“some_name”] has a length of 9 or less at which time the looping endsFrom the usage it looks like
jObject["Some_stream"]returns an array in that case what you could do is something like this:you will need to substitue TReal with the actual type of jObject[“Some_stream”]
aside: when ever you are opening a stream it’s a good idea to do this within a using statement. In your code the stream would not be closed in the case of an exception
the code would then be