Incorrect JSON Output Using ASP.NET - c#

Please excuse this question as a sign of frustration. While I understand that cause of the issue is the converting of data into different types, I can't put my finger on what's causing the result of this web service get method to be output incorrectly, that is containing backslashes.
The code below sums up the functionality of my method. I've tried different suggestions I found on these forums, some of which were in reply to similar questions I asked myself.
Data Model
public class WeatherResponse
{
public class Coord
{
public double lon { get; set; }
public double lat { get; set; }
}
public class Weather
{
public int id { get; set; }
public string main { get; set; }
public string description { get; set; }
public string icon { get; set; }
}
public class Main
{
public double temp { get; set; }
public int pressure { get; set; }
public int humidity { get; set; }
public int temp_min { get; set; }
public int temp_max { get; set; }
}
public class Wind
{
public double speed { get; set; }
public int deg { get; set; }
}
public class Clouds
{
public int all { get; set; }
}
public class Sys
{
public int type { get; set; }
public int id { get; set; }
public double message { get; set; }
public string country { get; set; }
public int sunrise { get; set; }
public int sunset { get; set; }
}
public class RootObject
{
public Coord coord { get; set; }
public List<WeatherResponse> weather { get; set; }
public string #base { get; set; }
public Main main { get; set; }
public int visibility { get; set; }
public Wind wind { get; set; }
public Clouds clouds { get; set; }
public int dt { get; set; }
public Sys sys { get; set; }
public int id { get; set; }
public string name { get; set; }
public int cod { get; set; }
}
}
Controller
[HttpGet]
public string Get(string city, string country)
{
string apiKey = "KEY";
HttpWebRequest apiRequest = WebRequest.Create("http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + country + " &appid=" + apiKey + "&units=metric") as HttpWebRequest;
string apiResponse = "";
using (HttpWebResponse response = apiRequest.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
apiResponse = reader.ReadToEnd();
}
Response.ContentType = "application/json";
return apiResponse;
}
Result
"{\"coord\":{\"lon\":-0.13,\"lat\":51.51},\"weather\":[{\"id\":521,\"main\":\"Rain\",\"description\":\"shower
rain\",\"icon\":\"09d\"}],\"base\":\"stations\",\"main\":{\"temp\":2.62,\"pressure\":991,\"humidity\":69,\"temp_min\":1,\"temp_max\":4},\"visibility\":10000,\"wind\":{\"speed\":5.1,\"deg\":90},\"clouds\":{\"all\":75},\"dt\":1548939000,\"sys\":{\"type\":1,\"id\":1414,\"message\":0.0037,\"country\":\"GB\",\"sunrise\":1548920401,\"sunset\":1548953318},\"id\":2643743,\"name\":\"London\",\"cod\":200}"
I need the code to simply retrieve weather data using the city and country received and correctly output it as JSON.

Here's the solution to the problem, as kindly posted by Joroen Mostert.
You should be able to use Content for this (when you change the return
type of your method to IActionResult): return Content(apiResponse,
"application/json") should not further escape.

Related

RestSharp API test running endlessly despite getting desired response - what am I missing out?

RestSharp beginner here; I browsed quite a bit but couldn't find the answers (or the ones I found didn't work out). I am trying to find out what I'm missing in my following test that's checking API response for a weather page.
Response code and content values are OK when I check using debugger but I can't figure out why test is running endlessly - apparently I am missing some important part. Added some Console.WriteLines that never get executed due to endless test.
Another issue is that I can't deserialize JSON file to custom created class (created by paste special in VS to avoid any more human made mistakes). Attaching code and example of JSON output below.
public async Task GetWeatherData()
{
var request = new RestRequest(url, Method.Get);
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.StatusCode);
if (response.IsSuccessful == true)
Console.WriteLine("Success!");
var output = response.Content;
Console.WriteLine(response.Content);
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
WeatherData responseData = JsonConvert.DeserializeObject<WeatherData>(output);
}
example of API output:
{"coord":{"lon":13.7329,"lat":46.1828},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"base":"stations","main":{"temp":298.23,"feels_like":298.13,"temp_min":296.13,"temp_max":301.58,"pressure":1008,"humidity":51},"visibility":10000,"wind":{"speed":2.71,"deg":223,"gust":2.23},"clouds":{"all":62},"dt":1653043444,"sys":{"type":2,"id":19828,"country":"SI","sunrise":1653017233,"sunset":1653071774},"timezone":7200,"id":3189038,"name":"Tolmin","cod":200}
Custom made class WeatherData (here also unsure if everything should be under one master class or is it fine like this):
public class WeatherData
{
public Coord coord { get; set; }
public Weather[] weather { get; set; }
public string _base { get; set; }
public Main main { get; set; }
public int visibility { get; set; }
public Wind wind { get; set; }
public Clouds clouds { get; set; }
public int dt { get; set; }
public Sys sys { get; set; }
public int timezone { get; set; }
public int id { get; set; }
public string name { get; set; }
public int cod { get; set; }
}
public class Coord
{
public float lon { get; set; }
public float lat { get; set; }
}
public class Main
{
public float temp { get; set; }
public float feels_like { get; set; }
public float temp_min { get; set; }
public float temp_max { get; set; }
public int pressure { get; set; }
public int humidity { get; set; }
}
public class Wind
{
public float speed { get; set; }
public int deg { get; set; }
public float gust { get; set; }
}
public class Clouds
{
public int all { get; set; }
}
public class Sys
{
public int type { get; set; }
public int id { get; set; }
public string country { get; set; }
public int sunrise { get; set; }
public int sunset { get; set; }
}
public class Weather
{
public int id { get; set; }
public string main { get; set; }
public string description { get; set; }
public string icon { get; set; }
}

Grabbing Json Data to String in Gridview

I'm setting up a website ASPX file that grabs the weather for the next 3 days, the output is in JSON and their classes are too complicated for me to understand it. If I want to extract just the weather for the next 3 days how do I go on about doing that?
https://samples.openweathermap.org/data/2.5/forecast?q=London,us&appid=b6907d289e10d714a6e88b30761fae22
This is the JSON output displayed on top.
What I'm trying to accomplish is to extract the next 3 days of the weather "Description" and put it to a GridView. I have used a JSON beautifier to get the classes but I am still confused.
Any help would be appreciated
This is my current code and I'm stuck here
protected void Button1_Click(object sender, EventArgs e)
{
string searchTerm = TextBox1.Text;
var webRequest = (HttpWebRequest)WebRequest.Create("https://samples.openweathermap.org/data/2.5/forecast?q=" + Server.UrlEncode(searchTerm) + "&units=metric&APPID=b6907d289e10d714a6e88b30761fae22");
var webResponse = (HttpWebResponse)webRequest.GetResponse();
if (webResponse.StatusCode == HttpStatusCode.OK)
{
Label1.Text = "The Next 3 days of weather in your area in" + searchTerm + " .";
JavaScriptSerializer json = new JavaScriptSerializer();
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
string resString = sr.ReadToEnd();
});
GridView1.DataSource = ?;
GridView1.DataBind();
}
else
Label.Text = "Invalid Response";
}
public class Main
{
public double temp { get; set; }
public double temp_min { get; set; }
public double temp_max { get; set; }
public double pressure { get; set; }
public double sea_level { get; set; }
public double grnd_level { get; set; }
public int humidity { get; set; }
public double temp_kf { get; set; }
}
public class Weather
{
public int id { get; set; }
public string main { get; set; }
public string description { get; set; }
public string icon { get; set; }
}
public class Clouds
{
public int all { get; set; }
}
public class Wind
{
public double speed { get; set; }
public double deg { get; set; }
}
public class Sys
{
public string pod { get; set; }
}
public class Rain
{
public double __invalid_name__3h { get;
set; }
}
public class Snow
{
public double __invalid_name__3h { get;
set; }
}
public class List
{
public int dt { get; set; }
public Main main { get; set; }
public List<Weather> weather { get; set; }
public Clouds clouds { get; set; }
public Wind wind { get; set; }
public Sys sys { get; set; }
public string dt_txt { get; set; }
public Rain rain { get; set; }
public Snow snow { get; set; }
}
public class Coord
{
public double lat { get; set; }
public double lon { get; set; }
}
public class City
{
public int id { get; set; }
public string name { get; set; }
public Coord coord { get; set; }
public string country { get; set; }
}
public class RootObject
{
public string cod { get; set; }
public double message { get; set; }
public int cnt { get; set; }
public List<List> list { get; set; }
public City city { get; set; }
}

Deserialize Json String to C# object

I'm trying out the Philips Hue lights api for the first time and I have a few questions on how to deserialize the json string to a C# object. I'm trying this out for the Xamarin.iOS app I'm working on.
Here's my method that would fetch the light data from around me:
private string getLights()
{
var url = APIURL + APIKey + LightsEndPoint ;
var request = WebRequest.Create(url);
request.ContentType = "application/json";
request.Method = "GET";
using (var response = request.GetResponse() as HttpWebResponse)
{
if (response.StatusCode != HttpStatusCode.OK)
Console.Out.WriteLine(
"Error fetching data. Server returned status code: {0}",
response.StatusCode);
using (var reader = new StreamReader(response.GetResponseStream()))
{
var content = reader.ReadToEnd();
if(string.IsNullOrWhiteSpace(content))
{
Console.WriteLine("Response contained empty body...");
}
else
{
Console.WriteLine("Response Body: \r\n {0}", content);
var items = JsonConvert.DeserializeObject <Light> (content);
}
return content;
}
}
}
Where Light is:
public class Light
{
public Light()
{ }
public string LightName { get; set;}
[JsonProperty("state")]
public string IsOn { get; set; }
[JsonProperty("sat")]
public int Saturation { get; set; }
[JsonProperty("bri")]
public int Brightness {get;set;}
[JsonProperty("hue")]
public int Hue { get; set; }
}
The problem I'm having now is my items object is always empty, null values even though I'm properly getting content json string.
My json string looks like this:
{
"1":{
"state":{
"on":true,
"bri":254,
"hue":20000,
"sat":100,
"effect":"none",
"xy":[
0.4146,
0.4155
],
"ct":299,
"alert":"none",
"colormode":"hs",
"reachable":true
},
"type":"Extended color light",
"name":"Hue color lamp 1",
"modelid":"LCT007",
"manufacturername":"Philips",
"uniqueid":"00:17:88:01:10:26:3f:12-0b",
"swversion":"5.38.1.14919"
},
"2":{
"state":{
"on":false,
"bri":254,
"hue":50000,
"sat":254,
"effect":"none",
"xy":[
0.2468,
0.0843
],
"ct":153,
"alert":"none",
"colormode":"hs",
"reachable":true
},
"type":"Extended color light",
"name":"Hue color lamp 2",
"modelid":"LCT007",
"manufacturername":"Philips",
"uniqueid":"00:17:88:01:10:5d:fd:f6-0b",
"swversion":"5.38.1.14919"
},
"3":{
"state":{
"on":true,
"bri":254,
"hue":10000,
"sat":254,
"effect":"none",
"xy":[
0.5711,
0.3986
],
"ct":500,
"alert":"none",
"colormode":"hs",
"reachable":true
},
"type":"Extended color light",
"name":"Hue color lamp 3",
"modelid":"LCT007",
"manufacturername":"Philips",
"uniqueid":"00:17:88:01:10:26:3d:17-0b",
"swversion":"5.38.1.14919"
}
}
The problem I'm having is light is indicated by a numerical value and I'm not sure how to split the json string to populate my c# object.
Basically, I'm having issues converting the json string to c# object for api stream for Xamarin.iOS app.
Your model should look like this
public class Light
{
public Light()
{
}
[JsonProperty("name")]
public string LightName { get; set;}
[JsonProperty("state")]
public State State { get; set; }
}
public class State
{
public State()
{
}
[JsonProperty("on")]
public bool IsOn { get; set; }
[JsonProperty("sat")]
public int Saturation { get; set; }
[JsonProperty("bri")]
public int Brightness {get;set;}
[JsonProperty("hue")]
public int Hue { get; set; }
}
And deserialization call should look like this
JsonConvert.DeserializeObject<Dictionary<string, Light>>(content);
Where the key of the dictionary is the numbers and value is the light model you want to get.
I generated a class with json2csharp:
public class State
{
public bool on { get; set; }
public int bri { get; set; }
public int hue { get; set; }
public int sat { get; set; }
public string effect { get; set; }
public List<double> xy { get; set; }
public int ct { get; set; }
public string alert { get; set; }
public string colormode { get; set; }
public bool reachable { get; set; }
}
public class RootObject
{
public State state { get; set; }
public string type { get; set; }
public string name { get; set; }
public string modelid { get; set; }
public string manufacturername { get; set; }
public string uniqueid { get; set; }
public string swversion { get; set; }
}
then I called this code:
var a = JsonConvert.DeserializeObject<Dictionary<string, RootObject>>(json);
and the result was this:
As mentioned, your model structure does not match that of the json's. You need to properly nest the properties accordingly. I threw together an example, though certain data types I was unsure of I simply used a string(Which should be fine).
Light.cs
public class Light
{
public string LightName { get; set; }
[JsonProperty("state")]
public State LightState { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("modelid")]
public string ModelId { get; set; }
[JsonProperty("manufacturername")]
public string Manufacturer { get; set; }
[JsonProperty("uniqueid")]
public string UniqueId { get; set; }
[JsonProperty("swversion")]
public string SwVersion { get; set; }
}
State.cs
public class State
{
[JsonProperty("on")]
public bool IsOn { get; set; }
[JsonProperty("bri")]
public int Brightness { get; set; }
[JsonProperty("hue")]
public int Hue { get; set; }
[JsonProperty("sat")]
public int Saturation { get; set; }
[JsonProperty("effect")]
public string Effect { get; set; } // Just making it a string for now
[JsonProperty("xy")]
public double[] XY { get; set; }
[JsonProperty("ct")]
public int CT { get; set; }
[JsonProperty("alert")]
public string Alert { get; set; } // Just making another string for now
[JsonProperty("colormode")]
public string ColorMode { get; set; } // Hey, it's another string for now
[JsonProperty("reachable")]
public bool Reachable { get; set; }
}
Then to deserialize:
var items = JsonConvert.DeserializeObject<Dictionary<string, Light>> (content);

Deserializing a JSON into a C# List of Objects

I am trying to Deserialize a JSON from google places api. My custom class is set up as follows and my code looks like this. My Program throws no errors when running but my places object is null.
class PlacesDictionary
{
public void placesDictionary()
{ }
public Places GetPlaces()
{
Places places = new Places();
string apiKey = "I have an apiKey";
string googleUrl;
googleUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=43.038902,-87.906474&radius=500&type=restaurant&name=cruise&key=" + apiKey;
WebRequest request = WebRequest.Create(googleUrl);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
places = JsonConvert.DeserializeObject<Places>(responseFromServer);
Console.WriteLine(responseFromServer);
Console.ReadLine();
reader.Close();
dataStream.Close();
response.Close();
return places;
}
}
public class Places
{
public List<Place> places { get; set; }
public class Place
{
public Geometry geometry { get; set; }
public string icon { get; set; }
public string id { get; set; }
public string name { get; set; }
public OpeningHours opening_hours { get; set; }
public List<Photo> photos { get; set; }
public string place_id { get; set; }
public int price_level { get; set; }
public double rating { get; set; }
public string reference { get; set; }
public string scope { get; set; }
public List<string> types { get; set; }
public string vicinity { get; set; }
public class Location
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Northeast
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Southwest
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Viewport
{
public Northeast northeast { get; set; }
public Southwest southwest { get; set; }
}
public class Geometry
{
public Location location { get; set; }
public Viewport viewport { get; set; }
}
public class OpeningHours
{
public bool open_now { get; set; }
public List<object> weekday_text { get; set; }
}
public class Photo
{
public int height { get; set; }
public List<string> html_attributions { get; set; }
public string photo_reference { get; set; }
public int width { get; set; }
}
}
}
I think you should use
List<Place> places = JsonConvert.DeserializeObject<List<Place>>(responseFromServer);
instead of
places = JsonConvert.DeserializeObject<Places>(responseFromServer);
and don't forget remove following line
Places places = new Places();
Edit: Full Answer
static void Main(string[] args)
{
string apiKey = "your api key";
string googleUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=43.038902,-87.906474&radius=500&type=restaurant&name=cruise&key=" + apiKey;
WebRequest request = WebRequest.Create(googleUrl);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
//StreamWriter wr = new StreamWriter("json.txt");
//wr.WriteLine(responseFromServer);
//wr.Flush();
//To see what it is inside json
Result results = JsonConvert.DeserializeObject<Result>(responseFromServer);
Console.WriteLine(responseFromServer);
Console.ReadLine();
reader.Close();
dataStream.Close();
response.Close();
}
}
public class Result
{
public List<HTMLAttribution> html_attributions { get; set; }
public string next_page_token { get; set; }
public List<Place> results { get; set; }
public string status { get; set; }
//Definations of Classes
public class HTMLAttribution { } //I don't what it is. It is empty for your url.
public class Place
{
public Geometry geometry { get; set; }
public string icon { get; set; }
public string id { get; set; }
public string name { get; set; }
public OpeningHours opening_hours { get; set; }
public List<Photo> photos { get; set; }
public string place_id { get; set; }
public int price_level { get; set; }
public double rating { get; set; }
public string reference { get; set; }
public string scope { get; set; }
public List<string> types { get; set; }
public string vicinity { get; set; }
public class Geometry
{
public Location location { get; set; }
public Viewport viewport { get; set; }
}
public class Location
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Viewport
{
public Northeast northeast { get; set; }
public Southwest southwest { get; set; }
}
public class Northeast
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Southwest
{
public double lat { get; set; }
public double lng { get; set; }
}
public class OpeningHours
{
public bool open_now { get; set; }
public List<object> weekday_text { get; set; }
}
public class Photo
{
public int height { get; set; }
public List<string> html_attributions { get; set; }
public string photo_reference { get; set; }
public int width { get; set; }
}
}
}
I would try something (if I were you) :
delete
Places places = new Places();
replace
places = JsonConvert.DeserializeObject(responseFromServer);
by
Places places = JsonConvert.DeserializeObject(responseFromServer);
and add a default constructor in your class Places like you have add in PlacesDictionary.
1.Just have Place class only.
2.Initialize List<Place> places=new List<Place>()
3.Deserialize using places
places = JsonConvert.DeserializeObject<places>(responseFromServer);

get data from json c#

I have a problem I want to get data from Json, and the data
successfully gets from the json to the variable json but when I want to send the data to WeatherData it send me a zero value.
I have one class that cald "WeatherData" and I want to send to data from the json (that existing a class "jsonParse") to this class.
jsonParse
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Web.Script.Serialization;
using System.IO;
namespace weather
{
public class jsonParse : Ijson
{
private string urlAdd;
public jsonParse(string _url)
{
if (_url == null)
{
//throw exption
}
else
urlAdd = _url;
}
public WeatherData parse()
{
//string json = new WebClient().DownloadString(urlAdd);
//var obj = JsonConvert.DeserializeObject<WeatherData>(json);
//Console.WriteLine(obj.temp);
// WeatherData m = JsonConvert.DeserializeObject<WeatherData>(json);
WebClient n = new WebClient();
var json = n.DownloadString(urlAdd);
string valueOriginal = Convert.ToString(json);
WeatherData m = JsonConvert.DeserializeObject<WeatherData>(json);
Console.WriteLine(m);
return m;
}
}
}
WeatherData
namespace weather
{
public class WeatherData
{
public WeatherData(double _temp, double _minTemp, double _maxTemp )
{
temp = _temp;
minTemp = _minTemp;
maxTemp = _maxTemp;
}
public double temp { get; set; }
public double minTemp { get; set; }
public double maxTemp { get; set; }
public override string ToString()
{
return "the weather:" + temp + "minTemp is:" + minTemp + "maxTemp:" + maxTemp;
}
}
}
json
{"coord":{"lon":139,"lat":35},
"sys":{"country":"JP","sunrise":1369769524,"sunset":1369821049},
"weather":[{"id":804,"main":"clouds","description":"overcast clouds","icon":"04n"}],
"main":{"temp":289.5,"humidity":89,"pressure":1013,"temp_min":287.04,"temp_max":292.04},
"wind":{"speed":7.31,"deg":187.002},
"rain":{"3h":0},
"clouds":{"all":92},
"dt":1369824698,
"id":1851632,
"name":"Shuzenji",
"cod":200}
If you only care about the weather part of the json, try this -
var o = (JArray)JObject.Parse(jsonString)["weather"];
foreach(JToken item in o)
{
Console.WriteLine(((JValue)item["id"]).Value);
Console.WriteLine(((JValue)item["main"]).Value);
Console.WriteLine(((JValue)item["description"]).Value);
Console.WriteLine(((JValue)item["icon"]).Value);
}
First object in json is coord, don't see that in your model.
You should change your JsonModel to deserialize. From c# class generator:
public class Coord
{
public int lon { get; set; }
public int lat { get; set; }
}
public class Sys
{
public string country { get; set; }
public int sunrise { get; set; }
public int sunset { get; set; }
}
public class Weather
{
public int id { get; set; }
public string main { get; set; }
public string description { get; set; }
public string icon { get; set; }
}
public class Main
{
public double temp { get; set; }
public int humidity { get; set; }
public int pressure { get; set; }
public double temp_min { get; set; }
public double temp_max { get; set; }
}
public class Wind
{
public double speed { get; set; }
public double deg { get; set; }
}
public class Rain
{
public int __invalid_name__3h { get; set; }
}
public class Clouds
{
public int all { get; set; }
}
public class RootObject
{
public Coord coord { get; set; }
public Sys sys { get; set; }
public List<Weather> weather { get; set; }
public Main main { get; set; }
public Wind wind { get; set; }
public Rain rain { get; set; }
public Clouds clouds { get; set; }
public int dt { get; set; }
public int id { get; set; }
public string name { get; set; }
public int cod { get; set; }
}
Where RootObject is your JsonConvert.DeserializeObject(json);
So you can change class names as you like.
Simply you cannot Deserialize a json object to a non-matching class object. So make sure you have a model object that have atleast all the properties that JSON object have.
In this case you would need following classes that are generated from your JSON object:
public class Coord
{
public int lon { get; set; }
public int lat { get; set; }
}
public class Sys
{
public string country { get; set; }
public int sunrise { get; set; }
public int sunset { get; set; }
}
public class Weather
{
public int id { get; set; }
public string main { get; set; }
public string description { get; set; }
public string icon { get; set; }
}
public class Main
{
public double temp { get; set; }
public int humidity { get; set; }
public int pressure { get; set; }
public double temp_min { get; set; }
public double temp_max { get; set; }
}
public class Wind
{
public double speed { get; set; }
public double deg { get; set; }
}
public class Rain
{
public int __invalid_name__3h { get; set; }
}
public class Clouds
{
public int all { get; set; }
}
public class ParentModel
{
public Coord coord { get; set; }
public Sys sys { get; set; }
public List<Weather> weather { get; set; }
public Main main { get; set; }
public Wind wind { get; set; }
public Rain rain { get; set; }
public Clouds clouds { get; set; }
public int dt { get; set; }
public int id { get; set; }
public string name { get; set; }
public int cod { get; set; }
}
ParentModel m = JsonConvert.DeserializeObject<ParentModel>(json);
Hope this helps.

Categories

Resources