logo
down
shadow

How to get value of a key in NSDictionary?


How to get value of a key in NSDictionary?

By : user2952639
Date : November 19 2020, 01:01 AM
wish of those help This is the userinfo of my silent push notification. How to get value of result in objective-c?
code :
NSLog(@"%@",[[Response valueForKey:@"aps"] valueForKey:@"result"]);


Share : facebook icon twitter icon
How do I copy individual Nested NSDictionary's from a NSDictionary to a temporary NSMutableDictionary

How do I copy individual Nested NSDictionary's from a NSDictionary to a temporary NSMutableDictionary


By : maxsimov
Date : March 29 2020, 07:55 AM
I hope this helps you . It looks like you're mixing up dictionaries with arrays.
Arrays respond to objectAtIndex whereas dictionaries respond to objectForKeys. Remember that an array is a set of cells that you can index into, starting from 0 all the way up to [array count] - 1.
code :
NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc] init];
[myDictionary setObject:anObject forKey:aKey];
NSDictionary *completeDictionary;
completeDictionary = [NSDictionary  dictionaryWithObjects:objectArray 
                      forkeys:keyArray count:[keyArray count]];
[myArray addObject:myObject];
myObject = [myDictionary objectForKey:key];
myObject = [myArray objectAtIndex:anIntegerIndex];
// assuming topLevelDictionary is previously defined
[topLevelDictionary setObject:[[dictionaryTwo copy] autorelease] forKey:myKey];
enumerating over a NSDictionary of a NSDictionary; extracting a certain key per NSDictionary element

enumerating over a NSDictionary of a NSDictionary; extracting a certain key per NSDictionary element


By : WHY
Date : March 29 2020, 07:55 AM
it should still fix some issue What you have is an NSDictionary with an NSArray that contains NSDictionarys.
Try this (not tested):
code :
NSArray *dictArray = [json objectForKey:@"result"];

for(NSDictionary *dict in dictArray){
    NSLog(@"dict = %@", [dict description]);
}
Convert NSArray containg NSDictionary objects into a single NSDictionary in IOS

Convert NSArray containg NSDictionary objects into a single NSDictionary in IOS


By : watoss
Date : March 29 2020, 07:55 AM
Hope that helps EDITED It makes no sense to use a dictionary to hold multiple values for the same key, so you must use an array:
code :
NSMutableArray *seatNumbers = [[NSMutableArray alloc] init];
for (NSDictonary *dict in passenger) {
    NSAssert([dict isKindOfClass:[NSDictionary class]], @"That array contains more than just dictionaries...");
    NSString *seatNumber = [dict objectForKey:@"seat_number"];
    if (seatNumber)
        [seatNumbers insertObject:seatNumber];
}
Cannot access protected member 'Foundation.NSDictionary.NSDictionary(System.IntPtr)'

Cannot access protected member 'Foundation.NSDictionary.NSDictionary(System.IntPtr)'


By : user3566807
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , According to Apple docs, PreferenceSpecifiers is an Array of dictionaries, so instead of doing this:
code :
NSDictionary prefSpecification = new NSDictionary(preferences.ValueAt(i));
NSDictionary prefSpecification = (NSDictionary)preferences.ValueAt(i);
UITableview with NSArray contains NSDictionary and NSDictionary containg another NSDictionary

UITableview with NSArray contains NSDictionary and NSDictionary containg another NSDictionary


By : Tite
Date : March 29 2020, 07:55 AM
will be helpful for those in need This is the response from Server side i am getting. matches is dictionary . , Try this code to get value from your json response
code :
NSMutableDictionary *dict= yourdata store in dictionary;

    for (int i=0; i<[dict allKeys].count; i++) {
        NSLog(@"%@",[dict objectForKey:[NSString stringWithFormat:@"%d",i]]);// return first array object means 0 key value
        NSLog(@"%@",[[dict objectForKey:[NSString stringWithFormat:@"%d",i]] objectForKey:@"shop_name"]);// return shop name

    }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.Shop_Name.text=[[yourJsonDictionary objectForKey:[NSString stringWithFormat:@"%d",indexPath.row]] objectForKey:@"shop_name"]; // print shop name 
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [yourJsonDictionary allKeys].count;
}
Related Posts Related Posts :
  • Convert from NStimeInterval to CMTime accurately
  • How can I continue my count from the correct spot once I load the saved count?
  • instance method 'connect:' not found (return type defaults to 'id'
  • Does an object initialize automatically if it is the synthesized property of another object?
  • What reasons are there to pass an argument to an initializer in objective C?
  • NSLogging UILabel's text outputs null
  • undefined reference to '__objc_class_name_Fraction'
  • Move UIView above UITableView when user Scrolls Down
  • adding object to nsmutablearray with custom delegate function giving error
  • Cocoa editing NSBezierPath
  • Perform a action on specific time using Parse
  • Objective-C: How to convert json value to BOOL?
  • How to make an int counter for the days
  • Assigning Label Value with Selected Table View Cell
  • SpriteKit - Preloader using GCD
  • Can dependency injection like Typhoon replace multiple singletons?
  • Objective C - How to determine if a folder is a package?
  • How can one draw a background in the elastic portion of an NSScrollView?
  • A solution for my issue with sending some info from an array to Parse
  • Swift Extension fails adding overloaded methods to Objective-C class
  • Determine if key is incorrect with CCCrypt kCCOptionPKCS7Padding-Objective C
  • PQgetResult always returns NULL
  • self.navigationController? is nil when pushing from a objective-c viewController to a Swift ViewController
  • Where to add subViews that I want floating in an NSScrollView using AutoLayout?
  • 'User' in 'User-defined classes'
  • Adding Border Line to UITableView in StoryBoard
  • Mac App Storyboard - Access Document in NSViewController
  • Objective c, reposition a view above the keyboard in one single animation
  • Dismiss modal segue
  • Error message is saying my data is NULL - NSKeyedUnArchiver - I've followed all the steps - still won't work
  • Remove apostrophe in CFStringTransform results
  • Label showing wrong values while NSLog shows the right ones in SpriteKit
  • How to work with locally modified Cocoapod which don't include podspec?
  • What does kCGWindowSharingState actually do?
  • It is possible to copy a CFTypeRef?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org