nsdictionary

Unrecognized selector error when indexing into a dictionary of arrays

*爱你&永不变心* 提交于 2019-12-02 04:22:36
I have a dictionary of arrays that is causing __NSCFDictionary objectAtIndex: errors. Can someone tell me why? The dictionary clearly has at least 1 array at the time of the error. NSError *error; responseString = [[NSString alloc] initWithData:self.responseData2 encoding:NSUTF8StringEncoding]; /* response string contains this: {"words": { "word": {"rowsreturned":0,"id":"-1","date":"","word":"","term":"","definition":"","updated_on":""} }, "status":"", "rowsreturned":"" } */ NSDictionary *json = [NSJSONSerialization JSONObjectWithData:self.responseData2 options:kNilOptions error:&error];

Get values from NSDictionary

时光毁灭记忆、已成空白 提交于 2019-12-02 02:46:44
问题 Hi I'm new to iOS development. I want to get response and add those values to variable. I tried it but I'm getting below response. I don't understand why there is slashes in this response. @"[{\"VisitorID\":\"2864983a-e26b-441a-aedf-84e2a1770b8e\",\"ProfileID\":\"69c02265-abca-4716-8a2f-ac5d642f876a\",\"CompanyID\":null,\"VisitorName\":\"kanasalingam\",\"OperatorName\":\"baman\",\"Image\":null,\"isocode\":\"lk\",\"CurrentOperator\":[\"69c02265-abca-4716-8a2f-ac5d642f876a\"]},{\"VisitorID\":\

Convert NSArray into array of JSON objects

青春壹個敷衍的年華 提交于 2019-12-02 02:35:01
问题 I'd like to create a JSON array of objects from the resultsArray. NSMutableArray *resultsArray = [NSMutableArray array]; FMResultSet *resultsSet = [database executeQuery:queryString]; while ([resultsSet next]) { [resultsArray addObject:[resultsSet resultDictionary]]; } For clarification, I'm using FMDB to query a database. I'm then storing the resulting objects within the resultsArray. From here I want to convert that results array into a JSON array of objects. 回答1: You can use

How to get Values without using Key from NSDictionary/NSMutableDictionary in iPhone?

爷,独闯天下 提交于 2019-12-02 02:20:24
问题 I have a webservice response in Json(Key and Value method) format. I parsed and get maximum of webservice methods. But, in one webservice method i can not get the values from key. Here i attaching the sample response, lessons = ( { "ObjectiveC Book" = ( { "brief_desc" = "ObjectiveC"; cost = 20; date = "2011-09-06"; }, { "brief_desc" = "ObjectiveC"; cost = 20; date = "2011-09-07"; }, { "brief_desc" = "ObjectiveC"; cost = 20; date = "2011-09-09"; }, { "brief_desc" = "ObjectiveC"; cost = 20;

-[__NSCFDictionary JSONRepresentation]: unrecognized selector sent to instance

眉间皱痕 提交于 2019-12-02 00:40:05
问题 I am using the json-famework available on github. I have added the reference for the project in my project, has added a header search path and imported JSON.h file in my viewController. I am trying to implement following code, where it gives me this error that JSONRepresentation is an unrecognized selector for NSDictionary object. Am I doing anything wrong in this case. Please guide me through. NSDictionary * profileDictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects

Convert NSArray into array of JSON objects

故事扮演 提交于 2019-12-01 23:52:09
I'd like to create a JSON array of objects from the resultsArray. NSMutableArray *resultsArray = [NSMutableArray array]; FMResultSet *resultsSet = [database executeQuery:queryString]; while ([resultsSet next]) { [resultsArray addObject:[resultsSet resultDictionary]]; } For clarification, I'm using FMDB to query a database. I'm then storing the resulting objects within the resultsArray. From here I want to convert that results array into a JSON array of objects. Andrew You can use NSJSONSerialization class to create a JSON file from your dictionary using the class method NSData * JSONData =

iOS — distinguish an NSDictionary from an NSMutableDictionary?

时光怂恿深爱的人放手 提交于 2019-12-01 23:32:44
I have the following code fragment: NSString* value = @"value"; NSString* key = @"key"; NSMutableDictionary* foo = [NSMutableDictionary dictionary]; NSDictionary* bar = [NSDictionary dictionary]; NSAssert([bar isKindOfClass: [NSMutableDictionary class]], @""); // passes the assert as both are NSCFDictionary; NSAssert([bar respondsToSelector: @selector(setValue:forKey:)], @""); // passes the assert because it NSCFDictionary does respond to the selector [foo setValue:value forKey:key]; // no problem, foo is mutable [bar setValue:value forKey:key]; // crash So if I have an object which is either

Sorting negative and positive numbers in objective c

人走茶凉 提交于 2019-12-01 21:15:28
I am listing out a quantity percentage like stuff for an item via a webservice.The response that I get is an array of dictionaries similar to the below code.I need it in a sorted format NSArray *numberArray = [NSArray arrayWithObjects: [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:-12.0], @"price", nil], [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:-86.0],@"price", nil], [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:-8.0],@"price", nil], [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:12.0],@"price", nil

Do instance references really work in Swift?

心已入冬 提交于 2019-12-01 17:59:58
I wrote the Objective-C code first NSMutableString *aStrValue = [NSMutableString stringWithString:@"Hello"]; NSMutableDictionary *aMutDict = [NSMutableDictionary dictionary]; [aMutDict setObject:aStrValue forKey:@"name"]; NSLog(@"Before %@",aMutDict); [aStrValue appendString:@" World"]; NSLog(@"After %@",aMutDict); I got the output as follows 2015-09-17 14:27:21.052 ShareIt[4946:129853] Before { name = Hello; } 2015-09-17 14:27:21.057 ShareIt[4946:129853] After { name = "Hello World"; } Means when I append a string to a Mutable string which is actually referred into a MutableDictionary, the

Do instance references really work in Swift?

徘徊边缘 提交于 2019-12-01 17:37:08
问题 I wrote the Objective-C code first NSMutableString *aStrValue = [NSMutableString stringWithString:@"Hello"]; NSMutableDictionary *aMutDict = [NSMutableDictionary dictionary]; [aMutDict setObject:aStrValue forKey:@"name"]; NSLog(@"Before %@",aMutDict); [aStrValue appendString:@" World"]; NSLog(@"After %@",aMutDict); I got the output as follows 2015-09-17 14:27:21.052 ShareIt[4946:129853] Before { name = Hello; } 2015-09-17 14:27:21.057 ShareIt[4946:129853] After { name = "Hello World"; } Means