Not able to pass special character into request - iphone

When I try to make request with some special character like japanese , then request is going to break and i am not able to get result. so my question is, how to pass special character in other language into request ?
Thanks in Advance.

You should encode your characters to UTF8 like this
NSString *encodedURL = [oldUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

Related

\ trimmed when sending data via NSURLRequest

I have a string which is a base64encoding of an audio file and looks like -"\/qwerty\/\/\/qwertyuiop". However, my server side developer says he just receives -"/qwerty///qwertyuiop". Which does not give the same result in decoding. So in what format do i send him that he will receive -"\/qwerty\/\/\/qwertyuiop" ? Please help.
I think what you want is to escape "\" from your URL. You can use BackSlash Escape Character.
Update :
You can use the Answer from these links :
URL encode an NSString
How do I do base64 encoding on iphone-sdk ?
Also take a look at this Beautiful Link : HTML URL Encoding Reference (Credit goes to HotLicks)
If I understood you correctly, here's what you need:
\\/qwerty\\/\\/\\/qwertyuiop
More about the escaping characters you can read here:Wiki

How to set line linebreak when passing parameters to Facebook

I am passing parameters to Facebook using JSON concept.I am passing Location name and Date in that. After location name i want to display Date in new line.Can any one help me how to give line break. Here is the my code.
Thanks in Advance.
NSString *att=[NSString stringWithFormat:#"{\"name\":\"%#\","
"\"href\":\"%#\","
"\"media\":[{\"type\":\"image\","
"\"src\":\"%#\","
"\"href\":\"%#\"}],"
"\"properties\":{\"Location\":\"%#\"\" Date\":\"%#\"}}",eventTitle.text,href,imageSource,imageHref,eventLocation.text,eventDate.text];
Not really a Facebook question. But certainly HTML-escaped spaces won't work.
You're probably looking for an escaped newline, \n
In fact, you'll need to escape it twice: once for NSString and once for JSON, ending up \n in your code

String encodiing Conversation in JSON response

I have a problem of string encoding. Actually I have a application, which is in 5 languages swedish, norwegian, english, finnish and danish. In one of section of my app, I get the review of user so it's possible to come in different language format like the word in swedish nämndes.
Now the problem is i get the response of review in JSOn format and the swedish character ä came as &a and it print as &a. i want to print as ä format. same in all language character problem.
Please help me...
I do something like this when Im requesting xml data from myserver.
NSString *responseString = [request responseString]; //Pass request text from server over to NSString
NSData *capturedResponseData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
Hope it helps.
Solution finally i change the web service character encoding. The web service Change the special word into UTF8 style encoding like /U00.. When we display in text or label it automatically converted and display specific word.

Escape characters in NSURLRequest

I'm trying to pass a request to a URL using HTTP POST on iPhone. The HTTP body contains some escape characters.
NSString *requestMessage=[NSString stringWithString:#"?username/u001password/u001description"];
NSMutableURLRequest *url=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"http://welcome.com"]];
[url setHTTPMethod:#"POST"];
[url setHTTPBody:[requestMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:url delegate:self];
The escape character here is /u001.
Using this code I don't get any correct responses. I think the trouble is with the escape characters only. Please give me a solution for how to give an escape sequence like this in Cocoa. Thanks in advance.
You've confused forward slashes (/) with backslashes (\). You need a backslash to form an escape sequence; a slash is just a slash, and “/u001” is just a slash, the letter u, two digits zero, and a digit one.
That said, if you actually want to include U+0001 in your string, even \u001 is wrong. You want \x01 or maybe \u0001 (but I seem to remember that GCC complains if you use \u for a character lower than U+0100).
I do wonder why the server would require U+0001 as the separator, though. Are there public API docs for whatever server you're querying?
What do you want to escape? I don't quite understand what you are trying to do. Do you want to write "&"? Then do it. It's not HTML.
Besides that, [NSString stringWithString:#"…constant string…"] is superfluid. #"…constant string…" is all you need.
There is a method in NSString to add percent-escapes to URLs: -(void)stringByAddingPercentEscapesUsingEncoding:. Maybe that's what you're looking for?

json parsing in objective c

while parsing the content of a .json file, string like "jamie's" is represented as "jamie 's".Any one know why it is so?
Make sure you are using application/json as a content type to transfer the data from the server to the client.
You can also go through following link
http://mobile.tutsplus.com/tutorials/iphone/iphone-json-twitter-api/
because the apostrophe is a special charachter and cant be transmitted inside of http packets. all special characters must be replaced with escape sequences like ' or with percent escapes %27 ...
in the NSString class you will find the methods 'stringByReplacingPercentEscapesUsingEncoding:' and 'stringByAddingPercentEscapesUsingEncoding:' for handle percent escapes.
the escape sequencies you must handle by yourself for example with 'stringByReplacingOccurrencesOfString:#"##039;" withString:#"'"' ...