简体   繁体   English

如何从字典中获得价值

[英]How to get value from dictionary

everyone! 大家!

Please help me to get the total value from given dictionary 请帮助我从给定的字典中获得总价值

 {
    "@averageBaseRate" = "296.7";
    "@averageRate" = "296.7";
    "@commissionableUsdTotal" = "1186.8";
    "@currencyCode" = USD;
    "@maxNightlyRate" = "296.7";
    "@nightlyRateTotal" = "1186.8";
    "@total" = "1186.8";
    NightlyRatesPerRoom =     {
        "@size" = 1;
        NightlyRate =         {
....

How can I get the value from total key. 我如何从总钥匙中获得价值。 Neither I can apply valueForKey nor I can apply objectForKey. 我既不能应用valueForKey也不能应用objectForKey。

Any help is highly appreciated ! 任何帮助都非常感谢!

It looks strange that you have "@total" instead of "total" - looks like @ is a part of NSString. 您使用“ @total”而不是“ total”看起来很奇怪-看起来@是NSString的一部分。 Probably you created a NSString @"@total" which sounds like a bug. 可能您创建了一个NSString @“ @ total”,听起来像个错误。 You should be able to access it with: 您应该可以通过以下方式访问它:

[dict objectForKey:@"@total"];

您可以使用它。

float total = [[yourDict objectForKey:@"@total"] floatValue];

Hey Buddy always use like this ........ 嘿伙伴总是这样使用........

with this line you get all value of ABC Key In your Array 通过这一行,您将获得阵列中所有ABC密钥的值

                 [array addObject:[dict objectForKey:@"ABC"]];

如今,您甚至可以使用yourDict[@"yourkey"]来获取为key存储的值。

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

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