心知天气:https://www.seniverse.com/
JSON:
{ "results": [ { "location": { "id": "C23NB62W20TF", "name": "西雅图", "country": "US", "path": "西雅图,华盛顿州,美国", "timezone": "America/Los_Angeles", "timezone_offset": "-07:00" }, "now": { "text": "多云", "code": "4", "temperature": "14", "feels_like": "14", "pressure": "1018", "humidity": "76", "visibility": "16.09", "wind_direction": "西北", "wind_direction_degree": "340", "wind_speed": "8.05", "wind_scale": "2", "clouds": "90", "dew_point": "-12" }, "last_update": "2015-09-25T22:45:00-07:00" } ] }
反序列:
using System.Collections; using System.Collections.Generic; using UnityEngine; [System.Serializable] public class listres { public List<ResponseData> results = new List<ResponseData>(); } [System.Serializable] public class ResponseData { public locationdata location; public nowdata now; public string last_update; } [System.Serializable] public class locationdata { public string id; public string name; public string country; public string path; public string timezone; public string timezone_offset; } [System.Serializable] public class nowdata { public string text; public int code; public int temperature; public int feels_like; public int pressure; public int humidity; public float visibility; public string wind_direction; public int wind_direction_degree; public float wind_speed; public int wind_scale; public int clouds; public string dew_point; } public class WeatherQuerier : MonoBehaviour { // Start is called before the first frame update IEnumerator Start() { WWW www=new WWW("https://api.seniverse.com/v3/weather/now.json?key=SGRa_X2yE0sr74OOd&location=beijing&language=zh-Hans&unit=c"); yield return www; print(www.text); listres respon =JsonUtility.FromJson<listres>(www.text); print(respon.results[0].location.path); } // Update is called once per frame void Update() { } }
标签:www,string,int,Unity,System,JSON,API,public,wind From: https://www.cnblogs.com/resucase/p/16847059.html