I have this JSON data i'm receiving from my webservice, the problem now is that i'm currently trying to retrieve the data outside square bracket, because my current codes is only able to retrieve the weather
data.
And whenever i try to get the data from coord
it keeps returning me the value 0.
{
"coord":{
"lon":145.77,
"lat":-16.92
},
"weather":[
{
"id":802,
"main":"Clouds",
"description":"scattered clouds",
"icon":"03n"
}
],
"base":"stations",
"main":{
"temp":300.15,
"pressure":1007,
"humidity":74,
"temp_min":300.15,
"temp_max":300.15
},
"visibility":10000,
"wind":{
"speed":3.6,
"deg":160
},
"clouds":{
"all":40
},
"dt":1485790200,
"sys":{
"type":1,
"id":8166,
"message":0.2064,
"country":"AU",
"sunrise":1485720272,
"sunset":1485766550
},
"id":2172797,
"name":"Cairns",
"cod":200
}
This is my current code i am trying to get the data from the curly bracket coord
but it keeps giving 0. Any help would be appreciated thanks!
public partial class Book : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public class Result
{
public string id{ get; set; }
public string main{ get; set; }
public string description{ get; set; }
public string icon{ get; set; }
public decimal lon{ get; set; }
}
public class SearchList
{
public int resultCount;
public Result[] weather;
}
protected void Button1_Click(object sender, EventArgs e)
{
string searchTerm = TextBox1.Text;
var webRequest = (HttpWebRequest)WebRequest.Create
("http://samples.openweathermap.org/data/2.5/weather?id=2172797&appid=b6907d289e10d714a6e88b30761fae22");
var webResponse = (HttpWebResponse)webRequest.GetResponse();
if (webResponse.StatusCode == HttpStatusCode.OK)
{
JavaScriptSerializer json = new JavaScriptSerializer();
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
string resString = sr.ReadToEnd();
SearchList list = json.Deserialize<SearchList>(resString);
GridView1.DataSource = list.weather;
GridView1.DataBind();
}
else
Label1.Text = "Invalid Response";
}
}