繁体   English   中英

解析AlamoFire的JSON输出

[英]Parse JSON output from AlamoFire

我正在使用最新的Alamofire来管理对服务器的GET http请求。 我正在使用以下内容来GET和解析JSON:

 Alamofire.request(.GET, "*******")
            .responseJSON {(request, response, JSON, error) in

                if let statusesArray = JSON as? NSArray{
                    if let aStatus = statusesArray[0] as? NSDictionary{

                        //OUTPUT SHOWN BELOW
                        println( "BREAKING DOWN \(aStatus)")

                        // This doesn't output anything?????
                        if let user = aStatus["title"] as? NSDictionary{
                            println( "TITLE \(user)")
                        }


                    }
                }

                println(JSON)

        }

GET请求有效,而我面临的问题是尝试在JSON输出中定位标题键。 println不输出任何内容。 我可以轻松地在目标C中执行此操作,但是由于某些原因,SWIFT使我感到困惑。 println的输出

BREAKING DOWN {
    "__v" = 0;
    "_id" = 5588468c65340938150f674f;
    endDate = 1435004396596;
    fullDescription = "Neutra blog McSweeney's pug Austin, put a bird on it fanny pack. Try-hard jean shorts trust fund vinyl kale chips, blog distillery pickled synth. Tofu fap Intelligentsia umami, McSweeney's pork belly church-key literally roof party crucifix lumbersexual meditation irony four loko. Mlkshk tousled before they sold out pork belly. PBR&B craft beer Tumblr, trust fund swag chillwave Truffaut.Retro cray narwhal 3 wolf moon. Pug master cleanse dreamcatcher, Vice Blue Bottle next level Helvetica messenger bag distillery chillwave pickled tattooed wayfarers DIY cold-pressed.";
    shortDescription = "Neutra blog McSweeney's pug Austin, put a bird on it fanny pack.";
    startDate = 1434994316596;
    title = "Artisanal Yoghurt";
}

如果我相信aStatus的println,则属性title是String而不是Dictionary。

更改代码中的这一部分(以字符串形式而不是NSDictionary形式):

if let user = aStatus["title"] as? String {
    println( "TITLE \(user)")
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM