Z
Z
ZederBreys2020-07-20 11:16:18
Computer networks
ZederBreys, 2020-07-20 11:16:18

c# how to work with json get request?

I work with vk api, when you click on the button, the following code is executed:

using (var request = new HttpRequest())
            {
                var urlParams = new RequestParams();

                string response = request.Get("https://api.vk.com/method/messages.getLastActivity?user_id=id&v=5.52&access_token=tokenc").ToString();

                string content = response.ToString();
                dynamic json = JObject.Parse(content);
            }

I get a response in the form:
"{\"response\":{\"online\":0,\"time\":1595229881}}"


Next, I form it into normal json and
get:
{{
  "response": {
    "online": 0,
    "time": 1595229881
  }
}}

It would seem that the song is sung on this, but in this language with json it’s not so simple, it turns out that it needs to be serialized, I tried many options, serialization and finally got confused.
How can you simply take the online or time parameter for example?

The library was used by Newtonsoft.Json

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Developer, 2020-07-20
@samodum

They returned normal correct JSON to you, and you broke it.


Then I form it into normal json and
get:
{{
"response": {
"online": 0,
"time": 1595229881
}
}}

You're generating JSON incorrectly. {{ and }} should not be. Replace with { and }
And on this the song will be sung.
Change the difficulty of the question to EASY

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question