简体   繁体   English

我如何从字典字典中获取数组中的值

[英]How do i get value in a array from dictionary of dictionaries

am calling a web service from my ios app , it returned dictionary of dictionaries,, like this 正在从我的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>

now i need to get all emails in a array how do i do this i tried this 现在我需要将所有电子邮件都整理成数组我该怎么做

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


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

but its returning nil,,can anybody help me out pls 但它返回零,有人可以帮我吗

You should try something like followings: 您应该尝试以下操作:

NSDictionary * Usernames = [[NSDictionary alloc]initWithContentsOfFile:strDocDirPath];
    for (NSDictionary *item in Usernames)
    {
        NSLog(@"%@",[item valueForKey:@"Email"]);
    }

它应该是一个逐步的过程,像这样尝试

NSLog(@"%@",[[Usernames valueForKey:@"first key"] valueForKey:@"second key"] );

Use this function of dictionary to enumerate and get all values of emails and store it into array. 使用字典的此功能可以枚举并获取电子邮件的所有值并将其存储到数组中。

  • (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, BOOL *stop))block (void)enumerateKeysAndObjectsUsingBlock:(void(^)(id key,id obj,BOOL * stop))块

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

相关问题 如何从字典数组中获取字典的数组(例如arrayGroupBy),其中某个键的值与另一个字典键的值匹配 - How to get an array(say arrayGroupBy) of dictionary from array of dictionary, where some key’s value are matching in another dictionary key’s value 如何从字典中获得价值 - How to get value from dictionary 如何从字典中检索一个数组,然后在该数组中检索字典? - How do I retrieve an array from a dictionary which and then retrieve a dictionary within that array? 从iOS中的数组获取字典值? - Get dictionary value from array in iOS? 如何获取字典值数组 - how to get the array of dictionary value count 如何访问词典数组中的特定密钥标书 - how do I access a specific key vale within an array of dictionaries 如何从包含字典的NSArray中获取最大值? - How to get the largest value from NSArray containing dictionaries? 将数据字典中的数据加载到目标C中的数组中,用于iphone应用程序 - Loading data from a dictionary of dictionaries into an array in Objective C for an iphone app 从字典数组中删除键值的重复项 - Removing duplicates of a key value from an array of dictionaries 如何在Objective C中访问字典数组并使用字典对象? - How to access array of dictionaries and use the dictionary objects in Objective C?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM