I have following code to convert my employee object in to JSON file :
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:emp.empName,@"name",emp.empId,@"empid",emp.empAddress,@"address",emp.mobile,@"mobile",nil];
NSData *jsonData=[NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
NSString *str=[[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"data =%@",str);
by using this code i am getting the JSON file. But I want to send this json as a httprequest body i have following code for this:
NSData *requestBody=[[NSString stringWithFormat:@"%@",str] dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:requestBody];
NSURLConnection *conn=[[NSURLConnection alloc]initWithRequest:request delegate:self];
But i am getting wrong json at the server side which cannot be parsed. Please suggest some solution on this problem. If i send JSON Data directly i got following json at server side which is wrong:
{ '{\n "name" : "vx",\n "mobile" : "8888888",\n "empid" : "96",\n "address" : "addre"\n}': '' }