ios swift http json
来源:互联网 发布:pkpm筒仓设计软件 编辑:程序博客网 时间:2024/05/18 20:51
json解析测试:http://www.douban.com/j/app/radio/channels
func get_data_from_url(url:String) { let httpMethod = "GET" let timeout = 15 let url = NSURL(string: url) let urlRequest = NSMutableURLRequest(URL: url, cachePolicy: .ReloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 15.0) let queue = NSOperationQueue() NSURLConnection.sendAsynchronousRequest( urlRequest, queue: queue, completionHandler: {(response: NSURLResponse!, data: NSData!, error: NSError!) in if data.length > 0 && error == nil{ let json = NSString(data: data, encoding: NSASCIIStringEncoding) // let enc = CFStringConvertEncodingToNSStringEncoding(0x0632) // let json = NSString( data: data, encoding:enc) // encoding:gbkEncoding // let json = NSString(data: data, encoding: NSUTF8StringEncoding) //self.extract_json(json) println(json) // self.praseJson(data) }else if data.length == 0 && error == nil{ println("Nothing was downloaded") } else if error != nil{ println("Error happened = \(error)") } } ) }
func praseJson(data: NSData) { var json: AnyObject = NSJSONSerialization.JSONObjectWithData(data,options:NSJSONReadingOptions.AllowFragments,error:nil)! var weatherInfos: AnyObject = json.objectForKey("channels")! //json结构字段名。 //var city:AnyObject = weatherInfo.objectForKey("name")! // json 数组 for result in weatherInfos as NSArray { var name = result.objectForKey("name") as NSString println(name) } // println(weatherInfo) }
0 0
- ios swift http json
- iOS Json解析Swift
- iOS Swift-Json解析
- IOS学习--- Swift JSON解析
- swift http请求返回json数据并解析
- swift http请求返回json数据并解析
- Swift: 用Alamofire做http请求,用ObjectMapper解析JSON
- SWIFT JSON
- Swift JSON
- ios发送HTTP请求和操作JSON
- iOS JSON与Object之间的映射 ObjectMapper For Swift
- iOS开发之Swift 4 JSON 解析指南
- iOS--swift
- Swift JSON 教程:使用 JSON
- iOS上的http请求和JSON解析
- http & json
- http+json
- Swift 与 JSON 数据
- android 滚动条
- AutoIt访问WebService
- mysql时间戳
- setOnClickListener
- Android Notification 通知栏
- ios swift http json
- ios swift 入门笔记
- ios swift tableview
- Android 跳转到市场给好评
- C++如何防止头文件被二次编译
- Android Timer(计时器)
- ios swift Button, Label, AlertView
- 20款优秀的移动产品原型和线框图设计工具
- 给UILabel 或者 UIButton标题加下划线