小编tat*_*ama的帖子

使用SwiftyJSON处理JSON的示例

我想用SwiftJSON处理json,但我堆叠了.有没有人给我看示例代码?

我试图使用这个库. https://github.com/SwiftyJSON/SwiftyJSON

虽然我在同一个项目中放置了SwiftyJSON.swift,但我有错误"没有这样的模块"SwiftyJSON""所以纠正我的代码或者向我展示使用swiftyJSON lib从web处理json的示例代码.

这是我的代码:

import UIKit
import SwiftyJSON // No such module "SwiftyJSON"

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let url = NSURL(string: "http://express.heartrails.com/api/json?method=getPrefectures")

        var request = NSURLRequest(URL: url!)
        var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: nil, error: nil)

        var json = NSJSONSerialization.JSONObjectWithData(data!, options: nil, error: nil) as NSDictionary

        var hoge = JSON(data)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources …
Run Code Online (Sandbox Code Playgroud)

json ios swift xcode6

18
推荐指数
2
解决办法
2万
查看次数

标签 统计

ios ×1

json ×1

swift ×1

xcode6 ×1