Traditional Culture Encyclopedia - Weather inquiry - How swift language nsurlsession asynchronously requests parsing json data
How swift language nsurlsession asynchronously requests parsing json data
func loadJsonData(){
//Define the interface address for obtaining json data. The API interface for obtaining weather is defined here. Another advantage is that swift statements do not need to be forced to use ";" At the end of each statement.
var URL = NSURL(string:"/data/sk/ 10 1 1 10 10 10 1 . html ")
//get JSON data
var data = ns data . datawithcontentsofurl(URL,options:NSDataReadingOptions。 DataReadingUncached, error: zero)
var JSON:any object = NSJSONSerialization。 JSONObjectWithData (data, options: NSJSONReadingOptions. AllowFragments, error: zero)
//Parse to get the JSON field value
Varweatherinfo: anyobject = json.objectforkey ("weatherinfo")//JSON structure field name.
var city:any object = weather info . objectforkey(" city ")
//etc. to get the information of other fields, so I won't go into details here.
//Then assign the obtained json value to the corresponding control.
Tv.text = "City: \(city)" // Use \ () to embed the variable into the corresponding string.
}
- Previous article:China Hongyedi 20 19 The Best Sightseeing Place of China Hongyedi
- Next article:What is strong convective weather?
- Related articles
- Why does the summer sun in the United States feel more sunny than in China?
- Gongtan weather
- What is the origin of Changchun place names?
- The current broadcast time of Foshan Radio Qianse 985 Animation Society.
- Why are there fish in the pool formed by rain?
- What other "forest weather stations" are there in the forest?
- How to set ink weather in HarmonyOS system?
- The weather is getting warmer and warmer.
- Recommended route in northwest go on road trip
- Why is autumn tiger called autumn tiger in 2022?