0

私は次のような辞書を持っています:

{
levels =     {
    exchange =         {
        text = ALL;
    };
    product =         {
        text = ALL;
    };
    segment =         {
        text = ALL;
    };
    symbol =         {
        text = ALL;
    };
};
marginavailable =     {
    adhocmargin =         {
        text = "0.00";
    };
    branchadhoc =         {
        text = "0.00";
    };
    cashmarginavailable =         {
        text = "0.00";
    };
    collateralvalue =         {
        text = "0.00";
    };
    credits =         {
        text = "0.00";
    };
    directcollateralvalue =         {
        text = "0.00";
    };
    notionalcash =         {
        text = 0;
    };
    payinamount =         {
        text = "0.00";
    };
};
marginutilised =     {
    adhocscripmargin =         {
        text = "0.00";
    };
    category =         {
        text = 0;
    };
    cncmarginused =         {
        text = 0;
    };
    cncsellcreditpresent =         {
        text = 0;
    };
    debits =         {
        text = "0.00";
    };
    elm =         {
        text = "0.00";
    };
    exposuremargin =         {
        text = "0.00";
    };
    grossexposurevalue =         {
        text = "0.00";
    };
    ipoamount =         {
        text = "0.00";
    };
    mfamount =         {
        text = "0.00";
    };
    multiplier =         {
        text = "0.00";
    };
    payoutamount =         {
        text = "0.00";
    };
    premiumpresent =         {
        text = "0.00";
    };
    realisedmtom =         {
        text = "-0.00";
    };
    scripbasketmargin =         {
        text = "0.00";
    };
    spanmargin =         {
        text = "0.00";
    };
    subtotal =         {
        text = "0.00";
    };
    turnover =         {
        text = "0.00";
    };
    unrealisedmtom =         {
        text = "-0.00";
    };
    valueindelivery =         {
        text = "0.0";
    };
    varmargin =         {
        text = "0.00";
    };
};
net =     {
    text = "0.00";
};

}

上記の辞書には、levels、marginavailable、marginutilized、net などの 4 つのキーが含まれています。

最初の 3 つのキーと最後のオブジェクトのオブジェクトを配列に入れたいと思っています。いろいろ試しましたが、解析するロジックが見つかりませんでした。

このような辞書の配列が欲しい

    exchange =         {
    text = ALL;
};
product =         {
    text = ALL;
};
segment =         {
    text = ALL;
};
symbol =         {
    text = ALL;
};
adhocmargin =         {
    text = "0.00";
};
branchadhoc =         {
    text = "0.00";
};
cashmarginavailable =         {
    text = "0.00";
};
collateralvalue =         {
    text = "0.00";
};
credits =         {
    text = "0.00";
};
directcollateralvalue =         {
    text = "0.00";
};
notionalcash =         {
    text = 0;
};
payinamount =         {
    text = "0.00";
};
adhocscripmargin =         {
    text = "0.00";
};
category =         {
    text = 0;
};
cncmarginused =         {
    text = 0;
};
cncsellcreditpresent =         {
    text = 0;
};
debits =         {
    text = "0.00";
};
elm =         {
    text = "0.00";
};
exposuremargin =         {
    text = "0.00";
};
grossexposurevalue =         {
    text = "0.00";
};
ipoamount =         {
    text = "0.00";
};
mfamount =         {
    text = "0.00";
};
multiplier =         {
    text = "0.00";
};
payoutamount =         {
    text = "0.00";
};
premiumpresent =         {
    text = "0.00";
};
realisedmtom =         {
    text = "-0.00";
};
scripbasketmargin =         {
    text = "0.00";
};
spanmargin =         {
    text = "0.00";
};
subtotal =         {
    text = "0.00";
};
turnover =         {
    text = "0.00";
};
unrealisedmtom =         {
    text = "-0.00";
};
valueindelivery =         {
    text = "0.0";
};
varmargin =         {
    text = "0.00";
};
net =     {
    text = "0.00";
};

前もって感謝します。

4

5 に答える 5

0

次のロジックを試すだけで、役立つ場合があります。

resultAry = [[NSMutableArray alloc]init];
[resultAry addObject:[[parentDictionary objectForKey:@"levels"]objectForKey:@"exchange"]];

そのように、キーからすべてのオブジェクトを追加しlevels、同じ方法でmarginavailableandを追加しますmarginutilised

そして最後に追加net

[resultAry addObject:[parentDictionary objectForKey:@"net"]];
于 2013-02-14T09:29:51.857 に答える
0

maindictionary に辞書が含まれている場合、このコードは有効です。

 NSMutableArray *dictionaryArray = [[NSMutableArray alloc]init];
        for (NSDictionary *childDictionaries in rootDict) { // rootDict is the original dictionary whic has all the four keys levels,marginAvailable,marginutilized and net

        for (NSDictionary *dict in childDictionaries) {
            [dictionaryArray addObject:dict];
        }
      }
于 2013-02-14T09:41:01.067 に答える