I have this JSON fetched from web service:
{"city":{"cityName":"*****","distance":0,"latitude":*****,"cityId":3,"longitude":*****}}
this works fine in web browsers but if I run my code in unity, unity just displays { }.
class Coordinate
{
public string cityName;
public string distance;
public string latitude;
public string cityId;
public string longitude;
}
NameValueCollection values = new NameValueCollection();
values.Add("latitude", latitude.ToString());
values.Add("longitude", longitude.ToString());
values.Add("radius_in_km", "0.5");
Debug.Log("Latitude: " + values.Get("latitude") + ", Longitude: " + values.Get("longitude") + ", radius_in_km: " + values.Get("radius_in_km"));
string url = "";
WWW www = new WWW(url);
Debug.Log("Requesting the following url: " + www.url);
yield return www;
Coordinate json = JsonUtility.FromJson<Coordinate>(www.text);
if(www.error == null)
{
Debug.Log(json.cityId);
Debug.Log("Loaded following JSON string " + JsonUtility.ToJson(www.text));
}
else
{
Debug.Log("ERROR: " + www.error);
}
The code just gives me { }. Am I missing something? I am fairly new to JSON and Unity