Reputation: 97
I am trying to convert two values to string and then make a new string containing the ones i made earlier so my service can accept them.
NSString *string1 = [ NSString stringWithFormat:@"%f", locationController.dblLatitude];
NSString *string2 = [ NSString stringWithFormat:@"%f", locationController.dblLongitude];
body = [[NSString stringWithFormat:@"geoX#%@#geoY#%@", string1, string2] dataUsingEncoding:NSUTF8StringEncoding];
This is the code i am using atm. The problem is that both string1 and string2 appear to be ok but the string named body appears to not working.. :< Any help ?
Upvotes: 0
Views: 131
Reputation: 1100
body
is not an NSString
instance here, but NSData
(because you're using `dataUsingEncoding:".
If you want to see concatenation of stings in system log you should write something like that:
NSString* bodyString = [NSString stringWithFormat:@"geoX#%@#geoY#%@", string1, string2];
NSData* bodyData = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
and then you can NSLog(@"Body: %@", bodyString);
to see it's contents and then use bodyData
for making http request.
Upvotes: 1
Reputation: 130193
I believe this is happening because you are just logging the raw data. Try creating a string from the data and then logging it like this:
body = [[NSString stringWithFormat:@"geoX#%@#geoY#%@", string1, string2] dataUsingEncoding:NSUTF8StringEncoding];
NSString *string = [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding];
NSLog(@"%@",string);
Upvotes: 1
Reputation: 3975
body
is not an NSString
; it is an NSData
because of your call to dataUsingEncoding
.
Upvotes: 1