1

我从我的 ios 应用程序调用 Web 服务,它返回字典字典,像这样

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>1</key>
    <dict>
        <key>Business classification</key>
        <string>a:2:{i:0;s:19:"Broker - Securities";i:1;s:18:"Financial Services";}</string>
        <key>Cell phone</key>
        <string>(2201258886</string>
        <key>Company position</key>
        <string>First Vice President - Wealth Management, CFP?</string>
        <key>Country</key>
        <string>UNITED STATES of AMERICA</string>
        <key>Email</key>
        <string>ravikirans@ms.com</string>
        <key>Full name</key>
        <string>llndrees</string>
        <key>Office phone</key>
        <string>(707) 571-5761</string>
        <key>Rkkkty/name</key>
        <string>Santkkka Roskka</string>
        <key>State</key>
        <string>Cakklifornia</string>
        <key>user_id</key>
        <string>1</string>
    </dict>
    <key>10</key>
    <dict>
        <key>Business classification</key>
        <string>a:1:{i:0;s:16:"Business advisor";}</string>
        <key>Cell phone</key>
        <string>415-491-4102</string>
        <key>Company position</key>
        <string>Business Adviser</string>
        <key>Country</key>
        <string>UNITED STATES of AMERICA</string>
        <key>Email</key>
        <string>bygttfn@pacbgf</string>
        <key>Full name</key>
        <string>Biolas</string>
        <key>Office phone</key>
        <string>415+656165402</string>
        <key>Rotuhuhame</key>
        <string>Tiburon</string>
        <key>State</key>
        <string>Caliggggfornia</string>
        <key>user_id</key>
        <string>13</string>
    </dict>

现在我需要在一个数组中获取所有电子邮件我该怎么做我试过这个

 NSDictionary * Usernames = [[NSDictionary alloc]initWithContentsOfFile:strDocDirPath];


            NSLog(@"%@",[Usernames valueForKey:@"Email"]);

但它返回零,任何人都可以帮助我吗?

4

3 回答 3

1

您应该尝试以下方法:

NSDictionary * Usernames = [[NSDictionary alloc]initWithContentsOfFile:strDocDirPath];
    for (NSDictionary *item in Usernames)
    {
        NSLog(@"%@",[item valueForKey:@"Email"]);
    }
于 2012-11-22T07:22:03.737 回答
0

使用字典的这个功能来枚举和获取电子邮件的所有值并将其存储到数组中。

  • (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, BOOL *stop))block
于 2012-11-22T07:21:05.230 回答
0

这应该是一个循序渐进的过程,试试这样

NSLog(@"%@",[[Usernames valueForKey:@"first key"] valueForKey:@"second key"] );
于 2012-11-22T07:18:14.763 回答