簡體   English   中英

我如何從字典字典中獲取數組中的值

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

正在從我的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"]);

但它返回零,有人可以幫我嗎

您應該嘗試以下操作:

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

它應該是一個逐步的過程,像這樣嘗試

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

使用字典的此功能可以枚舉並獲取電子郵件的所有值並將其存儲到數組中。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM