Reputation: 648
I'm developing an iOS application , that will take a twits from twitter, I'm using the following API
The problem are feed in Arabic Language , i.e the text feed appears like this
\u0623\u0646\u0643 \u0648\u0627\u0647\u0645
How can i get the real text (or how to encode this to get real text) ?
Upvotes: 3
Views: 337
Reputation: 112857
This is not encrypted, it is unicode. The codes 0600 - 06ff is Arabic. NSString handles unicode.
Here is an example:
NSString *string = @"\u0623\u0646\u0643 \u0648\u0627\u0647\u0645";
NSLog(@"string: '%@'", string);
NSLog output:
string: 'أنك واهم'
The only question is exactly what problem are you seeing, are you getting the Arabic text? Are you using NSJSONSerialization
to deserialize the JSON
? If so there should be no problem.
Here is an example with the question URL (don't use synchronous requests in production code):
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&count=2&screen_name=TareqAlSuwaidan"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSError *error;
NSArray *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
NSDictionary *object1 = [jsonObject objectAtIndex:0];
NSString *text = [object1 objectForKey:@"text"];
NSLog(@"text: '%@'", text);
NSLog output:
text: '@Naser_Albdya أيدت الثورة السورية منذ بدايتها وارجع لليوتوب واكتب( سوريا السويدان )
Upvotes: 5
Reputation: 1200
Those are Unicode literals. I think all that's needed is to use NSString
's stringWithUTF8String:
method on the string you have. That should use NSString
's native Unicode handling to convert the literals to the actual characters. Example:
NSString *directFromTwitter = [twitterInterface getTweet];
// directFromTwitter contains "\u0623\u0646\u0643 \u0648\u0627\u0647\u0645"
NSString *encodedString = [NSString stringWithUTF8String:[directFromTwitter UTF8String]];
// encodedString contains "أنك واهم", or something like it
The method call inside the conversion call ([directFromTwitter UTF8String]
) is to get access to the raw bytes of the string, that are used by stringWithUTF8String
. I'm not exactly sure on what those code points come out to, I just relied on Python to do the conversion.
Upvotes: 0