NSArray Returning String Instead of Dictionary
I've setup logs and checked the code and NSArray is being returned as a
string instead of a dictionary. The problem is that I'm not sure how I can
convert this particular string into a dictionary and I'm running on a
tight timeframe.
Here's the code:
NSArray* placeJson = [NSJSONSerialization JSONObjectWithData:jsonResponse
options:kNilOptions error:nil];
for (NSDictionary *placeJsons in placeJson) {
NSLog(@"%@",NSStringFromClass([placeJsons class]));
page = placeJsons[@"page"];
NSLog(@"%d",page);
if (page > 0) {
NSDictionary* pJson = placeJsons[@"data"];
for (NSDictionary *dict in pJson) {
Error in Logs and results of NSlog:
2013-09-12 19:50:55.117 GetDeal[1584:c07] __NSCFString
2013-09-12 19:50:55.118 GetDeal[1584:c07] -[__NSCFString
objectForKeyedSubscript:]: unrecognized selector sent to instance
0xac5f890
2013-09-12 19:50:55.119 GetDeal[1584:c07] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString
objectForKeyedSubscript:]: unrecognized selector sent to instance
0xac5f890'
This code may be useful as well.
NSLog(@"AES:%@",aesResponse);
NSData* jsonResponse = [aesResponse
dataUsingEncoding:NSUTF8StringEncoding];
NSArray* placeJson = [NSJSONSerialization
JSONObjectWithData:jsonResponse options:kNilOptions error:nil];
Sorry. The JSON data:
http://mobapps.getdeal.me/getcoupons.php?category=art
Possible supe solution:
NSArray* placeJson = [NSJSONSerialization JSONObjectWithData:jsonResponse
options:kNilOptions error:nil];
NSDictionary *placeJsons = [NSJSONSerialization
JSONObjectWithData:[placeJson
dataUsingEncoding:NSUTF8StringEncoding]
Error Message.
No visible @interface for 'NSArray' declares the selector
'dataUsingEncoding:'
Definitely sorry... but in about 30 minutes my life is going to change
dramatically.
Answer to Martin:
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding
allowLossyConversion:NO];
NSString *postLength = [NSString stringWithFormat:@"%d", [post
length]];
**NSURL *url = [NSURL URLWithString:placeLink];**
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
Config.h
#define placeLink @"http://mobapps.getdeal.me/getcoupons3.php"
No comments:
Post a Comment