无法在swift中为对象设置类型JSON

时间:2015-09-19 10:24:27

标签: ios json xcode swift

大家好我在使用Xcode 7和swift2但是由于一些奇怪的原因我无法设置JSON类型的数据对象,我尝试使用不同的类型,它们似乎出现了在intellisense上但由于某种原因JSON在以前是可用的时候可用..

我得到的错误是

使用未声明的类型JSON

这是我在空白快速文件中的数据格式,值得注意的是,使用JSON这个词并不像往常那样变绿。

var data: JSON = [

    "stories" : [

        [
            "Article_Link" : "http://www.webdesignernews.com/redirect?url=http%3A%2F%2Fwww.creativebloq.com%2Fweb-design%2Fweb-designers-take-centre-stage-new-sitcom-91516753",
            "Article_Shares" : "",
            "Article_Time" : "44 min ago",
            "Article_Title" : "Web Designers Take Centre Stage in New Sitcom",
            "icon" : "Web-Designer-Depot",
            "index" : 2,
            "source" : "Web Designer Depot",
            "url" : "http://www.webdesignernews.com/",
        ],
        [
            "Article_Link" : "http://www.webdesignernews.com/redirect?url=http%3A%2F%2Fwww.webdesignerdepot.com%2F2015%2F09%2Fwhats-new-for-designers-september-2015%2F",
            "Article_Shares" : "203",
            "Article_Time" : "50 min ago",
            "Article_Title" : "What's New for Designers, September 2015",
            "icon" : "Web-Designer-Depot",
            "index" : 3,
            "source" : "Web Designer Depot",
            "url" : "http://www.webdesignernews.com/",
        ],
        [
            "Article_Link" : "http://www.webdesignernews.com/redirect?url=http%3A%2F%2Fblog.atomic.io%2Fnews%2Fadvanced-motion-control-now-in-atomic%2F",
            "Article_Shares" : "68",
            "Article_Time" : "1 hour ago",
            "Article_Title" : "New in Atomic Prototype with Advanced Motion Control + Swipe Gestures",
            "icon" : "Web-Designer-Depot",
            "index" : 4,
            "source" : "Web Designer Depot",
            "url" : "http://www.webdesignernews.com/",
        ]

       ]
    ]

1 个答案:

答案 0 :(得分:1)

编译器拥有抛出该错误的所有权利。 Swift中不存在名为JSON的数据类型。你应该使用字典。