Jossy Paul
Jossy Paul

Reputation: 1287

How to access NSArray inside a NSDictionary while parsing a xml?

I am using XMLReader to parse a xml response. I have converted the xml to a NSDictionary. Now i want to access the array named 'cTrx' inside the NSDictionary. This is my NSDictionary:

{
Envelope =     {
    Body =         {
        fRetrieveTransactionsforReversalResponse =             {
            fRetrieveTransactionsforReversalResult =                 {
                pCellularNumber =                     {
                    text = 0825669995;
                };
                pResponseCode =                     {
                    text = 00;
                };
                pResponseMessage =                     {
                    text = Approved;
                };
                pTrx =                     {
                    cTrx =                         (
                                                    {
                            pCardHolderName =                                 {
                            };
                            pReference =                                 {
                                text = 140826121114;
                            };
                            pTransactionAccount =                                 {
                                text = "364241****0016";
                            };
                            pTransactionDate =                                 {
                                text = "8/26/2014 12:11:18 PM";
                            };
                            pTransactionID =                                 {
                                text = 23;
                            };
                        },
                                                    {
                            "xsi:nil" = true;
                        }
                    );
                };
            };
        };
    };
};
}

Thanks.

Upvotes: 0

Views: 121

Answers (1)

kelin
kelin

Reputation: 12021

You can access dictionary and array values with square brackets:

val = dictionary[@"key"];
item = array[i];

It works for nested dictionaries as well:

NSDictionary *nested = @{@"dict_key": dictionary};
dictionaryVal = nexted[@"dict_key"][@"key"];

So, in your case, you could access cTrx array in next way:

NSArray *cTrx = yourDictionary[@"Envelope"][@"Body"][@"fRetrieveTransactionsforReversalResponse"][@"pTrx"][@"cTrx"];

Long string of code :)

Upvotes: 1

Related Questions