Getting information from a NSDictionary

半城伤御伤魂 提交于 2019-12-24 15:33:27

问题


I named the result resultdict and the NSDictionary looks like this:

{
    data =     (
    );
    summary =     {
        "total_count" = 514;
    };
}

How do I get the "514" from that? I am using swift.


回答1:


You can just do it like :

var totalCount = yourDict.objectForKey("summary").objectForKey("total_count")

convert it to string

var totalCount = yourDict.objectForKey("summary").objectForKey("total_count") as! String

If you use :

println(totalCount)

will result in

Optional(514)

Use that variable as you want




回答2:


Try this one

 var totalCount = yourDict.valueForKeyPath("summary.total_count")


来源:https://stackoverflow.com/questions/31363762/getting-information-from-a-nsdictionary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!