Chaaruu Jadhav
Chaaruu Jadhav

Reputation: 484

JSON parsing is sending error message in iOS 7.1

I checked my code but not getting what is wrong with my code..I am working on JSON Parsing using post method.this same code is working in Xcode 5 but it is not working in Xcode 6.Getting Bellow error in my JSONSerialization.

 parsingResultLogin = {
   "error_code" = "-1";
   "error_message" = "";
  }

My code is -

-(void)loginFromServer
{
   NSString *strURL = [NSString stringWithFormat:@"%@login",GLOBALURLDOMAIN];
   NSLog(@"strURL =%@",strURL);
   NSData *dataPostLogin = nil;
   NSDictionary *dicPostDataLogin = [ NSDictionary dictionaryWithObjectsAndKeys:@"qwertyuiopwqq",@"username",@"qwertyuiop",@"password",@"1234567890987654",@"device_token",@"ios",@"device_type", nil];
   NSLog(@"%@",[dicPostDataLogin description]);
   dataPostLogin = [NSJSONSerialization dataWithJSONObject:dicPostDataLogin options:NSJSONWritingPrettyPrinted error:nil];
   NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];
   NSLog(@"request = %@",request);
   [request setHTTPBody:dataPostLogin];
   [request setHTTPMethod:@"POST"];
   [request setValue:[NSString stringWithFormat:@"%lu",(unsigned long)[dataPostLogin length]] forHTTPHeaderField:@"Content-Length"];
   [request setValue:@"JSON/application" forHTTPHeaderField:@"Content-Type"];
   NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
   NSLog(@"responsedata =%@",responseData);
   if (responseData == NULL) {
      AppDelegate *appdel = [[UIApplication sharedApplication]delegate];
      [appdel alertError];
   }
   else
   {
       NSDictionary *parsingResultLogin = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
    NSLog(@"parsingResultLogin = %@",parsingResultLogin);
    //NSString *strParseDataResult = [parsingResultLogin objectForKey:@""];
   }
}

Upvotes: 0

Views: 105

Answers (1)

gnasher729
gnasher729

Reputation: 52530

Key/values in JSON are separated by ":", not "=". And there should be no semicolon at the end. So this isn't valid JSON and isn't going to parse with a JSON parser.

Upvotes: 2

Related Questions