- Home /
Question by
nhudinh2103 · Jul 24, 2016 at 08:43 AM ·
c#unity 5json
JsonUtility with openweatherAPI
Here's my JSON API in:
{
coord: {
lon: 105.85,
lat: 21.03
},
weather: [
{
id: 800,
main: "Clear",
description: "clear sky",
icon: "01n"
}
],
base: "stations",
main: {
temp: 297.897,
pressure: 1009.91,
humidity: 92,
temp_min: 297.897,
temp_max: 297.897,
sea_level: 1018.33,
grnd_level: 1009.91
},
wind: {
speed: 1.93,
deg: 181.501
},
clouds: {
all: 0
},
dt: 1469311176,
sys: {
message: 0.0124,
country: "VN",
sunrise: 1469226442,
sunset: 1469273919
},
id: 1561096,
name: "Xóm Pho",
cod: 200
}
Here's my classes:
WeatherData.cs
[System.Serializable]
public class WeatherData {
public Coord cord;
public Weather[] weather;
public string @base;
public Main main;
public Wind wind;
public Clouds clouds;
public uint dt;
public Sys sys;
public int id;
public string name;
public int cod;
public void Load(string savedData)
{
JsonUtility.FromJsonOverwrite(savedData, this);
}
}
Coord.cs
[System.Serializable]
public class Coord
{
public float lon;
public float lat;
}
Other classes (Weather, Base, Main ...) worked fine. But when serialized Coord object, value of lon and lat not correct (lon = lat = 0.0f). Can somebody explain me why?
Comment
Best Answer
Answer by Bunny83 · Jul 24, 2016 at 11:36 AM
Well:
cord != coord
You named your variable wrong.