Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从JSON iOS解析数据_Json_Swift - Fatal编程技术网

如何从JSON iOS解析数据

如何从JSON iOS解析数据,json,swift,Json,Swift,我正在iOS中使用SWIFT构建一个应用程序,我也一直在使用swiftyJSON来简化这个项目 func parseJSON(){ let path : String = NSBundle.mainBundle().pathForResource("jsonFile", ofType: "json") as String! let url : String = "http://www.thegoodsite.org/attend/api.php?users_id=1" l

我正在iOS中使用SWIFT构建一个应用程序,我也一直在使用swiftyJSON来简化这个项目

func parseJSON(){
    let path : String = NSBundle.mainBundle().pathForResource("jsonFile", ofType: "json") as String!
    let url : String = "http://www.thegoodsite.org/attend/api.php?users_id=1"
    let nsurly = NSURL(string: url)
    let jsonData = NSData(contentsOfURL: nsurly!) as NSData!
    let readableJSON = JSON(data: jsonData, options: NSJSONReadingOptions.MutableContainers, error: nil)

    var Name = readableJSON

    numberOfRows = readableJSON["People"].count //Ignore this for the question



    NSLog("\(Name)")

}
我正在从一个url加载这些数据,所以如果要包含一个数据的图片,我将返回控制台

那么,我需要添加什么代码才能将电子邮件显示为文本呢

var Name = readableJSON ["users","email"]
然而,当我对代码这样做时,我似乎根本没有得到任何数据

如何编辑此代码以获得所需的电子邮件

let users = readableJSON["users"]
let user = users[0] // get info of the first user, you should check more here
let email = user["email"]
或(作为@nhgrif的cmt):


我播放代码,然后找到Json if字典的结果,所以使用
var Name=readableJSON[“users”]!![0][“email”]

以纯文本形式发布控制台输出,而不是指向屏幕上带有控制台输出的照片的链接。
如果让用户=readableJSON[“users”],用户=users。首先,email=user[“email”]
@nhgrif谢谢。我使用
[0]
,因为OP可以像
[I]
那样进行调整。如果数组为空,
[0]
将崩溃。@nhgrif我如何才能将该电子邮件作为string@BrandonMayU请在询问之前尝试。如果不是传统的,是字典,对不起,
if let users = readableJSON["users"], user = users.first, email = user["email"]