当存在objectforkey时,Object For Key返回Null



我正在运行for循环,但它找不到键的对象。我试着在中放入if语句,看看它是否会有任何不同的结果,但它没有记录

这是我的描述字典(它的日志)

{
    (
    "Apple's big event: Here's what to expect",
    "WeChat helps Apple rack up bonus points in China",
    "China Mobile Wants Apple's iPhone 6 to be a Blowout Success",
    "What Will Apple Announce On September 9th? Software and Hardware Predictions For The iPhone 6 Event",
    "Apple seeks old magic with new products",
    "Five ways Apple's iPhone 6, iWatch launches may transform its business model",
    "Apple's Plan To Kill PayPal Has Finally Become Clear (AAPL)",
    "Apple's mojo on the line at unveiling",
    "Will Apple",
    "Apple adds new Flyover Tours Before the Big Launch for iOS 8 and OS X Yosemite ",
    "Apple: watching for new directions",
    "Apple Looks to Fashion World for iWatch Rollout",
    "Apple website to live stream iPhone 6 launch event only for Apple devices",
    "Is Apple planning a catwalk show for its iPhone/iWatch event?"
) =     (
    "After months of anticipation, the tech industry event of 2014 is upon us: Apple's product launch day. The tech giant has said almost nothing publicly about what's in store Tuesday, but industry observers have some ideas. Apple (AAPL, Tech30) is widely ...",
    "BEIJING (Reuters) - Apple Inc has a lot for which to thank people like Deng. A Beijing-based quality analyst, she gave only her surname as she's embarrassed by how much money she spends playing mobile games on WeChat, a hugely popular messaging app ...",
    "Apple Store in Pudong Shanghai. Source: Apple. Earlier this week the world's largest mobile carrier, China Mobile (NYSE: CHL ) , launched a pre-order site for the new, not-yet-released Apple (NASDAQ: AAPL ) iPhones. It wasn't the first time the carrier has ...",
    "For fans and followers, journalists and analysts, to pop culture experts, celebrities, and late night chat show hosts, this Tuesday is going to be just like Christmas Day. While Apple has not said what will be announced at its September 9th event ...",
    "With its highly awaited product launch this week, Apple is aiming for a new ",
    "Apple is building a giant white cube outside of the Flint Center in Cupertino, CA. James Martin/CNET Apple's launch of the larger screen iPhone 6 and preview of iWatch or a similar wearable will aim to silence critics who contend the company's innovation ...",
    "Apple has been quietly putting together a plan to blow open the mobile-payments industry, making major deals with credit-card companies in a move that could threaten the dominance of PayPal and other mobile-payment companies. These deals could make Apple ...",
    "SAN FRANCISCO ",
    "Just this past week we released our tour of Motorola",
    "Apple knows they need to work on Maps. Improving their product started with faster turnarounds for updates and correcting errors and it continues with 3D flyover tours for more an more cities. A flyover tour will not make the Maps app more useful, but it ...",
    "San Francisco (AFP) - Apple's mystery unveiling on Tuesday is expected to be a watershed moment for the California giant -- and the entire tech industry. Here are key things to watch for: - Can Tim Cook step up? - Chief executive Tim Cook will seek to ...",
    "As intrigue builds around the mystery wearable product Apple is rumored to be launching next week, a new thread has been added to the story: high fashion. According to a new report, fashion journalists have been invited to Apple's Sept. 9 event, a move ...",
    "The Apple launch event is the most teased event for a while now, and this made the Apple to want every Apple users to watch the video by streaming the event on the Apple website. Apple wants each and everyone on this globe to watch the launch event of the ...",
    "There's a mysterious white building being built at the site of Apple's Tuesday event. Fashion bloggers have been invited. Ergo? Could there be a glorious catwalk lurking inside Apple's mystery cube? James Martin/CNET I took all my clothes to the dry ..."
);
}

这是我的一组密钥

"Apple's big event: Here's what to expect",
"WeChat helps Apple rack up bonus points in China",
"What Will Apple Announce On September 9th? Software and Hardware Predictions For The iPhone 6 Event",
"Apple's Plan To Kill PayPal Has Finally Become Clear (AAPL)",
"China Mobile Wants Apple's iPhone 6 to be a Blowout Success",
"Apple's mojo on the line at unveiling",
"Five ways Apple's iPhone 6, iWatch launches may transform its business model",
"Apple seeks old magic with new products",
"Apple: watching for new directions",
"Apple Looks to Fashion World for iWatch Rollout",
"Will Apple",
"Apple adds new Flyover Tours Before the Big Launch for iOS 8 and OS X Yosemite ",
"Is Apple planning a catwalk show for its iPhone/iWatch event?",
"Apple Hires Australia"

当我运行这个for循环时,它总是不记录

for(NSString *string in _titleArray) {
    if([_descriptionDict objectForKey:string]) {
        NSLog(@"YES");
    } else {
        NSLog(@"NO");
    }
}

编辑由于第一个答案,我们知道字典是这样的,问题还在继续。如何将其转换为普通字典

**********编辑***********我似乎根据答案正确地形成了它们,这就是的形成方式

    descForTitles = [NSDictionary dictionaryWithObject:descriptions forKey:titleArr];
    NSLog(@"Description Dict:%@", descForTitles);

但我最终还是以相同的方式记录

看起来您的原始字典是一个大数组到另一个大阵列的映射。字典应该像这样设置

@{@"key": @"object",
  @"otherKey": @"otherObject"};

它会像这样记录:

{
key = object;
otherKey = otherObject;
}

括号表明映射的每一侧都有一个数组。

你有更像这样的东西:

@{@[@"key", @"otherKey"]:
  @[@"object", @"otherObject"]};

像这样的日志,看起来像你所拥有的。

{
(
    key,
    otherKey
) =     (
    object,
    otherObject
);
}

如果您首先将这些数据作为数组获取,则可以考虑使用NSDictionary类方法[NSDictionary dictionaryWithObjects: forKeys:],该方法将两个数组作为参数,并将正确地构建一个将其中一个与另一个关联的字典。

相关内容

最新更新