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"
I will give it a try. As I said in a comment, your provider sends "nested JSON":
NSURL *url = [NSURL URLWithString:@"http://mobapps.getdeal.me/getcoupons.php?category=art"];
NSData *jsonResponse = [NSData dataWithContentsOfURL:url];
NSLog(@"%@", [[NSString alloc] initWithData:jsonResponse encoding:NSUTF8StringEncoding]);
Output:
"{\"data\":[[{\"PID\":\"90205\",\"PName\":null, ... ,\"page\":\"1\"}"
This is JSON data once more encoded as a JSON string. The first task is to remove the outer JSON encoding:
NSError *error;
NSString *outerJson = [NSJSONSerialization
JSONObjectWithData:jsonResponse
options:NSJSONReadingAllowFragments error:&error];
NSLog(@"%@", outerJson);
Output:
{"data":[[{"PID":"90205","PName":null, ... ,"page":"1"}
So now we have proper JSON data, which can be de-serialized:
NSDictionary *innerJson = [NSJSONSerialization
JSONObjectWithData:[outerJson dataUsingEncoding:NSUTF8StringEncoding]
options:0 error:&error];
NSLog(@"%@", innerJson);
Output:
{ data = ( ( { PAddr = "Save 20-85% on select artwork in the closeout section. Just click the link, then click \"paintings on closeout\" toward the bottom of the page. No code necessary, prices are as marked."; PCity = ""; ... rate = 20; sao = 20; }; } ); 페이지 = 1; }
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다