簡體   English   中英

從字典解析字典中的所有內容

[英]Parsing arrary of dictionaries from dictionary

解析XML文件后,輸出將以以下格式出現在字典中現在我想將其轉換為字典數組
任何人都可以提出適當的解決方案

Printing description of rootDictionary:
<CFBasicHash 0x8866000 [0x1078b38]>{type = mutable dict, count = 1,
entries =>
    0 : <CFString 0x8869490 [0x1078b38]>{contents = "Data"} = <CFBasicHash 0x88695c0 [0x1078b38]>{type = mutable dict, count = 1,
entries =>
    0 : <CFString 0x8869610 [0x1078b38]>{contents = "row"} = (
        {
        Address =         {
            text = "Skt. Clemens Torv 2-6";
        };
        City =         {
            text = "Aarhus C";
        };
        Country =         {
            text = Danmark;
        };
        Description =         {
            text = Ottopiste;
        };
        Lat =         {
            text = "56.156818";
        };
        Lon =         {
            text = "10.2092532";
        };
        Name =         {
            text = Ottopisteet;
        };
        Type =         {
            text = 1;
        };
        Zip =         {
            text = 8000;
        };
    },
        {
        Address =         {
            text = "Kauppatie 66";
        };
        City =         {
            text = Kauhava;
        };
        Country =         {
            text = Finland;
        };
        Description =         {
            text = "(null)";
        };
        Lat =         {
            text = "63.1001586";
        };
        Lon =         {
            text = "23.0463634";
        };
        Name =         {
            text = I m Here;
        };
        Type =         {
            text = 2;
        };
        Zip =         {
            text = 62200;
        };
    }
)
}
}

現在輸出字典是上面的格式,現在我想將其轉換成字典數組

Actual format of XML for reference:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Data>
<row>
  <Lat>56.156818</Lat>
  <Lon>10.2092532</Lon>
  <City>Aarhus C</City>
  <Address>Skt. Clemens Torv 2-6</Address>
  <Zip>8000</Zip>
  <Country>Danmark</Country>
  <Name>Ottopisteet</Name>
  <Description>Ottopiste</Description>
  <Type>1</Type>
</row>
<row>
  <Lat>63.1001586</Lat>
  <Lon>23.0463634</Lon>
  <City>Kauhava</City>
  <Address>Kauppatie 66</Address>
  <Zip>62200</Zip>
  <Country>Finland</Country>
  <Name>I am Here</Name>
  <Description>(null)</Description>
  <Type>2</Type>
</row>
</Data>

做這個:

 NSMutableArray *arrData = [[parsedValueDictionary objectForKey:@"Data"]  objectForKey:@"row"];

您可以只對行的字典進行迭代,然后將每個對象添加到數組中:

NSMutableArray *arrayOfDictionaries = [[NSMutableArray alloc] init];
NSDictionary *rows = [rootDictionary objectForKey:@"Data"];

[rows enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop){
  [arrayOfDictionaries addObject:obj];
}];

更新 :我假設在“數據”字典中只有“行”條目。 否則,如果之前是“行”,則應檢查si的

暫無
暫無

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

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