0

I am getting error during json parsing. When I trying to send the parameters using browser then it send me the success message that record store successfully. But when I send form parameters through iphone then i get nothing and in array i get NULL value.This is the json parsing code.

  NSString *string1 = [[NSString alloc]initWithFormat:@"http://195.78.76.34/bedspace/mobileapi.php?action=save_room_info&Area=%@&Address=%@&Living_room=%@&Amenties=%@&Type_of_cost=%@&cost_of_room=%@&Security_deposit=%@&STLC=%@&Days_available=%@&Bill_included=%@&Broadband_available=%@&Exc_Smoke=%@&Exc_gender=%@&Exc_pets=%@&Exc_age=%@&Exc_language=%@&Exc_nationality=%@&Exc_Sexorientition=%@&Exc_intrest=%@&Pre_smoke=%@&Pre_gender=%@&Pre_occupation=%@&Pre_pets=%@&Pre_min_age=%@&Pre_max_age=%@&Pre_nationaltiy=%@&Pre_Language=%@&Pre_Sexorientition=%@&Misc=%@&Title=%@&Description=%@&Your_name=%@&Your_email=%@&Email_alert=%@&No_of_rooms=%@&Country=%@&City=%@&State=%@&Size_of_property=%@&Type_of_property=%@&Occupets_property=%@&My_property_status=%@&Amenties_two=%@&Size_of_room=%@&Refrence_required=%@",area,address,livingRoomVal,amenties,typeOfCost,costOfRoom,securityDeposit,STLC,daysAvailable,billsIncluded,broadbandAvailable,eSmoke,eGender,ePets,eAge,eLanguage,eNationality,eSexOrientation,eInterest,pSmoke,pGender,pOccupation,pPets,pMinAge,pMaxAge,pNationality,pLanguage,pSexOrientation,misc,title,description,yourName,yourEmail,emailAlerts,noOfRooms,country,city,state,sizeOfProperty,typeOfProperty,occupentsOfProperty,myPropertyStatus,amentiesTwo,sizeOfRoom,refrenceRequired];
    NSLog(@"string 1 value %@",string1);
    NSURL *urlRequest = [NSURL URLWithString:string1];
    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:urlRequest];
   NSData *dataResponce = [NSURLConnection sendSynchronousRequest:request returningResponse:Nil error:Nil];

    NSError *jsonParsingError = nil;
    NSArray *publicTimeline = [NSJSONSerialization JSONObjectWithData:dataResponce options:0 error:&jsonParsingError]; 
 NSLog(@"get values %@",publicTimeline);

I don't know what the problem is. I also used SBJsonParser but i get nothing in array and after that I used NSJSONSerialization and same problem still happen i got nothing in NSData and in NSArray.

6
  • what error log display? Commented Feb 19, 2013 at 8:02
  • Try to use NSMutableURLRequest and set HTTP method POST, this may help you Commented Feb 19, 2013 at 8:03
  • what is the parameter value? Commented Feb 19, 2013 at 8:04
  • brother i used this same code to store registration form records and it store successfully and i have done json parsing 100 of times to store the records in database and fetch records from database and get successfully i don't know why i getting error to Commented Feb 19, 2013 at 8:04
  • on nslog i getting null value in nsarray and also i log nsdata and it returning null as well Commented Feb 19, 2013 at 8:05

1 Answer 1

4

You cannot fill the URL with parameters and still expect it to be legal, so you need to URL Encode the URL before use:

NSURL *urlRequest = [NSURL URLWithString:[string1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.