M
M
maksustoff2017-04-05 16:36:30
JSON
maksustoff, 2017-04-05 16:36:30

Parsing json in C# (request in VK API). Where is the error?

You need to parse the ID's of the user's friends.
We get a stream.

private Stream GetRequest(string url)
        {
            var request = HttpWebRequest.Create(url);
            var WebResponse = request.GetResponse();
            Stream stream = WebResponse.GetResponseStream();
            return stream;
        }

We create the response class.
public class Response
    {
        public int count { get; set; }
        public List<int> items { get; set; }
    }

We translate the stream into a string. Deserialize.
string DeserStr = "";
            using (StreamReader str = new StreamReader(GetRequest(requestURL)))
            {
                DeserStr = str.ReadToEnd();

            }
            Response respons = JsonConvert.DeserializeObject<Response>(DeserStr);

Json itself (there ID's are smeared, don't be afraid :)).
b5b5cc945b1d4cb094f068b7d63f4092.jpg
Can't deserialize, what's the problem? Please help, thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2017-04-05
@maksustoff

It would deserialize if it was just like this:
And you also have {"response":... at the beginning
Change the class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question