Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3949434
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:29:35+00:00 2026-05-20T01:29:35+00:00

I have a dictionary/list balance_sign_dict from which I need to retrieve 2 values based

  • 0

I have a dictionary/list balance_sign_dict from which I need to retrieve 2 values based on condition.
The source XML for this is;

<Value>
<Signature>-873</Signature>
<Amount>1501042000</Amount>
</Value>

I want to parse data from the dict shown below;
Could you please tell me how do I parse conditional data (e.g. if I want the value of “Amount” node for “Signature” node having -873) i.e. it should return me 1501042000

I want a generic way of parsing the values from the dictionary below.

Printing description of balance_sign_dict:

(
        {
        nodeChildArray =         (
                        {
                nodeContent = "-873";
                nodeName = Signature;
            },
                        {
                nodeContent = 1501042000;
                nodeName = Amount;
            }
        );
        nodeName = Value;
    },
        {
        nodeChildArray =         (
                        {
                nodeContent = "-1228";
                nodeName = Signature;
            },
                        {
                nodeContent = 428586000;
                nodeName = Amount;
            }
        );
        nodeName = Value;
    },
        {
        nodeChildArray =         (
                        {
                nodeContent = "-1140";
                nodeName = Signature;
            },
                        {
                nodeContent = 79370000;
                nodeName = Amount;
            }
        );
        nodeName = Value;
    },

Here is what I am trying now;

for (NSDictionary *valueNode in balance_sign_dict){
            for (NSArray *nodeChildArray in [valueNode objectForKey:@"nodeChildArray"]){
                NSString *tmpNodeName = [nodeChildArray objectAtIndex:1];
                NSDictionary *tmpD = [valueNode objectAtIndex:1];


                if ([tmpNodeName isEqualToString:@"Signature"]) {
                    tmpSignVal = [nodeChildArray objectAtIndex:0];
                    if ([tmpSignVal isEqualToString:@"-873"]) {
                        tmpSignAmt = [nodeChildArray objectAtIndex:1];
                    }
                }

But for some reason the 2nd part of nodeChildArray gets removed…i.e. nodeContent = 1501042000;
nodeName = Amount;

I am not sure how to access that part.

Please help.
}
}

Actually here is what i get during alternate runs;

Printing description of nodeChildArray:
{type = mutable dict, count = 2,
entries =>
0 : {contents = “nodeName”} = {contents = “Signature”}
1 : {contents = “nodeContent”} = {contents = “-1507”}
}

Printing description of nodeChildArray:
{type = mutable dict, count = 2,
entries =>
0 : {contents = “nodeName”} = {contents = “Amount”}
1 : {contents = “nodeContent”} = {contents = “631000”}
}

How do I get the Amount value for matching Signature value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:29:36+00:00Added an answer on May 20, 2026 at 1:29 am

    NSArray and NSDictionary are the best container classes that I know of in any language that I am experienced with. NSDictionary can store any object or primitive, including an NSArray, and vice versa. When I say dictionary I am arbitrarily referring to either class.

    When you output the description of any dictionary (which is as simple as NSLog(@"%@",myDict);, the entire contents of the dictionary are displayed like an XML (or maybe more accurately a JSON) document. It is easy to look at the content of the dictionary description to determine what is contained inside. () denotes an NSArray and {} denotes an NSDictionary.

    // this is the beginning of an array.
    (
            // this is the beginning of index 0 of the array, an `NSDictionary`
            {
            // objectForKey:@"nodeChildArray"] isKindOfClass:[NSArray class]]
            nodeChildArray =         ( // inside nodeChildArray is another array
                            { // index 0 of array is a dictionary with two keys
                    // objectForKey:@"nodeContent" == @"-873"
                    nodeContent = "-873";
                    // objectForKey:@"nodeName" == @"Signature"
                    nodeName = Signature;
                }, // end of index 0
                            { // index 1 of array
                    nodeContent = 1501042000;
                    nodeName = Amount;
                } // end of index 1
            ); // end of nodeChildArray, an NSArray stored at objectForKey:@"nodeChildArray"
            // this is the only other element in the dictionary, a string
            // objectForKey:@"nodeName"] isKindOfClass:[NSString class]]
            nodeName = Value;
        }, // end of the dictionary containing nodeChildArray and nodeName
            { // objectAtIndex:1
            nodeChildArray =         (
                            {
                    nodeContent = "-1228";
                    nodeName = Signature;
                },
                            {
                    nodeContent = 428586000;
                    nodeName = Amount;
                }
            );
            nodeName = Value;
        },
            { // objectAtIndex:2
            nodeChildArray =         (
                            {
                    nodeContent = "-1140";
                    nodeName = Signature;
                },
                            {
                    nodeContent = 79370000;
                    nodeName = Amount;
                }
            );
            nodeName = Value;
        },
    );
    

    So you can see from looking at your NSDictionary debug output that it’s actually an NSArray. The order of structures is NSArray->NSDictionary->NSArray->NSString <--> [[[[NSArray objectAtIndex:i] NSDictionary objectForKey:@"nodeChildArray"] NSArray objectAtIndex:j] NSDictionary objectForKey:@"nodeContent"], finally returning an NSString. Use this as the most recent code – in the last version of the code I passed balance_sign_dict as an NSDictionary. This might have even worked! But it is much better form to cast the argument properly. If you don’t know whether or not your dictionary is going to start with an NSArray or an NSDictionary, you can cast it as an id and check its type with [theIdObject isKindOfClass:[{NSArray,NSDictionary} class]]. Don’t use the {} and choose one of the two in your code.

    -(NSDictionary*)parseBalance:(NSArray*)balance_sign_dict
    {
      NSMutableDictionary* theResults = [NSMutableDictionary dictionary];
      for( NSDictionary* nodeDict in balance_sign_dict )
      {
        NSArray* nodeChildArray = [nodeDict objectForKey:@"nodeChildArray"];
        [theResults addObject:[[nodeChildArray objectAtIndex:1] objectForKey:@"nodeContent"] forKey:[[nodeChildArray objectAtIndex:0] objectForKey:@"nodeContent"]];
      }
      return theResults;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list string tag. I am trying to initialize a dictionary with
A lot of the collection classes in .Net (i.e., List<T>, Dictionary<TKey, TValue>) have an
I have a dictionary of 200,000 items (the keys are strings and the values
I have a dictionary that I normally access with a key, so I need
I have a dictionary where keys are strings, and values are integers. stats =
I have a Dictionary that when I add multiple values to it, the items
I have found this example on StackOverflow: var people = new List<Person> { new
i have a input tag which is non editable, but some times i need
I have a Dictionary<string, someobject> . EDIT: It was pointed out to me, that
I have a Dictionary where I hold data for movieclips, and I want the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.