简体   繁体   中英

Parse data from JSON API(URL) c#

I am trying to parse JSON data from this API:

I wrote that on Main Form:

void button1_Click(object sender, EventArgs e)
{
    using (var webClient = new System.Net.WebClient())
    {
        var json = webClient.DownloadString("URL");
        var user = JsonConvert.DeserializeObject<User>(json);
        MessageBox.Show(User.callsign);
    }
}

And I created a class where I convert JSON data to strings with JSONProperty:

public class User
{
    [JsonProperty("callsign")]
    public string callsign { get; set; }
}

The problem is that when I try the MessageBox.Show(user.callsign) on the main form, I can´t. Because the button1 void is static and the callsign string is not. What can I do??

Regards!!

You are using the Class name and not the variable name. C# is case sensitive.

Change it to this:

MessageBox.Show(user.callsign);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM