Getting information from a NSDictionary

2019-08-05 12:40发布

问题:

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")