swift 官方获取JSON 数据方法

 var url = NSURL(string: "http://www.weather.com.cn/data/sk/101120501.html")

        var data = NSData(contentsOfURL: url!, options: NSDataReadingOptions.DataReadingUncached, error: nil)

        var json : AnyObject! = NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions(), error: nil)

        var weatherinfo: AnyObject? = json.objectForKey("weatherinfo")

        var city: AnyObject? = weatherinfo?.objectForKey("city")

        

        //  println(city)

 

 

swiftyJSON

 

////        // var url = NSURL(string: API_HOST+"/"+LOGIN_API)

//////        var url = NSURL(string: "http://www.weather.com.cn/data/sk/101120501.html")

//////        let data = NSData(contentsOfURL: url!, options: NSDataReadingOptions.DataReadingUncached, error: nil)

 

//////        

//////        //  println(city)

//////        let jsonS = JSON(data: data!)

//////        println(jsonS)

//////        println(jsonS[0]["weatherinfo"].string)

//////        if let info = jsonS["weatherinfo"].string{

//////            println(info)

//////        }

 

posted on 2014-11-19 15:14  studyphp  阅读(951)  评论(0编辑  收藏  举报

导航