I am slowly learning JSON responses and how to handle them with JSON.net
The data i am obtaining can be found here
http://www.bom.gov.au/fwo/IDN60901/IDN60901.95764.json
As an example i am trying to pull out the "Copyright" info from the "notice" section of that json
I can successfully pull the data down but i'm not sure its being deserialized properly. Nothing is appearing in the textbox that i have defined to show the data in the code but the data is being pulled down as i can display the raw response in the second textbox as i have defined in the ode.
Can you please let me know what i am doing wrong
Thanks :)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.Web;
using Newtonsoft.Json.Linq;
namespace RESTTEST2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class notice
{
public string copyright { get; set; }
public string copyright_url { get; set; }
public string disclaimer_url { get; set; }
public string feedback_url { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Text = "test";
string url = "http://www.bom.gov.au/fwo/IDN60901/IDN60901.95764.json";
HttpWebRequest req = WebRequest.Create(url)
as HttpWebRequest;
req.Credentials = CredentialCache.DefaultCredentials;
req.ContentType = "application/json";
string result = null;
using (HttpWebResponse resp = req.GetResponse()
as HttpWebResponse)
{
StreamReader reader =
new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
richTextBox2.Text = result;
var bar = Newtonsoft.Json.JsonConvert.DeserializeObject<notice>(result);
var bar2 = bar.copyright_url;
var bar3 = result.ToString();
richTextBox1.Text = bar2;
}
}
}
}
