Swift Basics-Parsing server JSON content

Source: Internet
Author: User

viewcontroller.swift//jieparsejson////Created by Jiezhang on 14-10-5.//Copyright (c) 2014 Jiezhang. All rights Reserved.//import Uikitclass Viewcontroller:uiviewcontroller {@IBOutlet Weak V    Ar city:uilabel!    @IBOutlet weak var cityid:uilabel!    @IBOutlet weak var temp1:uilabel!    @IBOutlet weak var temp2:uilabel!    @IBOutlet weak var weather:uilabel!    @IBOutlet weak var img1:uilabel!    @IBOutlet weak var img2:uilabel!            @IBOutlet weak var ptime:uilabel! Override Func Viewdidload () {super.viewdidload ()} override func didreceivememorywarning () {Super.di Dreceivememorywarning ()} func GetWeather () {var url = nsurl (string: "http://www.weather.com. Cn/data/cityinfo/101010100.html ") var data = NSData (contentsofurl:url) var str = nsstring (Data:data, Encod ing:nsutf8stringencoding) println (str) var json:anyobject! = Nsjsonserialization.jsonoBjectwithdata (data, options:NSJSONReadingOptions.AllowFragments, error:nil) Let Weatherinfo:anyobject = Json.obj        Ectforkey ("Weatherinfo")!        City.text = Weatherinfo.objectforkey ("City") As String cityid.text = Weatherinfo.objectforkey ("Cityid") As String Temp1.text = Weatherinfo.objectforkey ("Temp1") as String Temp2.text = Weatherinfo.objectforkey ("Temp2") as St Ring Weather.text = Weatherinfo.objectforkey ("Weather") as String Img1.text = Weatherinfo.objectforkey ("Img1 ") As String img2.text = Weatherinfo.objectforkey (" Img2 ") As String ptime.text = Weatherinfo.objectforkey (" p Time ") as String} @IBAction func Updateweather (sender:anyobject) {GetWeather ()}}


I wanted to show the picture, but the returned picture was fake, I looked at the page,<big class= "jpg80 n01" ></big> in CSS.

Big.jpg80{background-image:url (.. /.. /i/weather2014/jpg/gray80.jpg); Height:80px;width:80px}.on Big.jpg30{background-image:url (.. /.. /i/weather2014/jpg/white30.jpg); Height:30px;width:31px}.on Big.jpg50{background-image:url (.. /.. /i/weather2014/jpg/blue50.jpg); Height:50px;width:50px}.on Big.jpg80{background-image:url (.. /.. /i/weather2014/jpg/blue80.jpg); height:80px;width:80px}.sk Big.jpg80{background-image:url (.. /.. /i/weather2014/jpg/blue80.jpg); height:80px;width:80px}
So the real address: http://i.tq121.com.cn/i/weather2014/jpg/blue80.jpg, opened after a group of pictures, like the following, on the site is to see the CSS cut out.








Swift Basics-Parsing server JSON content

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.