String encodiing Conversation in JSON response - iphone

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.

Related

Not able to pass special character into request

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];

special character issue in text getting from CMS

I am using API to get data from CMS, we are displaying text what user has entered into CMS,
But my problem is when user enter some special character into CMS,I am not able to get those text on iphone side
Here is the link of text what user has entered in wall description
We are using json web service, they are encode string to utf-8 so my json string will be
The word 'stop' isn\u0092t in your vocabulary. Run a marathon in 4.5 hours or less.
The utf character \u0092 is a special character we need to display same in shown in above image
NOTE:
1)if we pass string without encoding to utf-8 in webservice,I am getting whole string as null .
2)I have try with [NSString stringWithCString:[textFromCms cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding];
where textFromCms is text I got from cms as show above.
3)I also try without any conversation/encoding ….it ignore the special character
4)also try with base64 but did not help that also.
Any help would be so appreciated.
The CMS apparently uses windows-1252, not UTF-8. The curly apostrophe is 92 (hex) in windows-1252, U+2019 in Unicode, so when properly encoded into JSON, it should be \2019.

Decoding HTML entities on iPhone

I have a list of several locations, some of them containing the letters æ, Æ, ø, Ø, å and Å.
From the webservice I'm using, the letters comes out as "&oslash ;" "&Aring ;" etc.
When I download the feed from the webservice, I use UTF-8 encoding.
How can I decode the occurences of these characters?
Thanks!
There is no standard way, to make it simple write your own custom method (or NSString extension) and do this :
string = [string stringByReplacingOccurrencesOfString:#"&" withString:#"&"];
If your webservice is using utf8 and if you decode the data with [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding], all should be ok.
A NSString category called "GTMNSString+HTML" written by Google works perfectly for me. Check it out here: https://gist.github.com/takuma104/ntlniph/blob/master/gtm/Foundation/GTMNSString+HTML.h & here: https://gist.github.com/takuma104/ntlniph/blob/master/gtm/Foundation/GTMNSString+HTML.m

convert XML encoded in Windows-1252 to UTF8 encoding

I've been trying to solve the encoding conversion problem without any luck so far. I found many suggestions on Stack Overflow how to tackle the problem like converting the XML string into NSData that uses UTF8 encoding, but the result was the same, my Spanish tildas are presented as weird chars. This is what I am using to grab the xml:
//Convert Win 1252 encoding of the string to UTF8
NSString *xmlString = [NSString stringWithContentsOfURL:[NSURL URLWithString:chosenDrawRss] encoding:NSWindowsCP1252StringEncoding error:&error];
If I call the above method with encoding UTF8 app crushes...
I tried converting the string into NSData using UTF8 and then back to NSString but still I had no luck. I wish I could simply change the XML file encoding but unfortunately that is out of my hands :(
When printed to NSLog everything is presented as it should be whether Im printing the XML string or the NSData created from that string...
BEst regards,
L
UPDATE: I haven't found the solution for the encoding mess :(. Since I found out that my Win1252 encoded RSS was also containing some HTML that I wanted to get rid of I wrote a .php script that I am calling from iPhone. This .php script parses the original XML from the remote server. This .php script is in UTF8; does some html cleaning and reorders the XML elements so in my case it made sense doing it is this way. Unfortunately, I still have no clue how to read a win1252 encoded XML and convert it to UTF8 directly from iOS :(((

Japanese character encoding problem on iPhone

I am encountering a problem concerning text-encoding on iPhone. I retrieve japanese characters from a sqlite database. So I get character like that ( their ASCII representation here : "& #25104;& #12395;& #12424;& #12427;" )
When I display these characters on a WebView, my japanese characters are well displayed. But when I try to display them on a UILabel, the ASCII representation is displayed rather than the japanese one.
I retrieve the text data from the database with the following function :
NSString *watchText = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
If anyone has an idea...
That's because what you have is not an "ASCII representation". Those ("成による") are known as XML or HTML character entity references. As such, they only work if you parse them in an HTML context (like a web view).
What you need to do is either use a UIWebView for your labels, or parse the character entity references to turn them in to a normal NSString.