Reputation: 443
I am a newbie in iOS development. I parsed a JSON Data From URL like as:
http://www.janvajevu.com/webservice/specific_post.php?post_id=2885
And I parsed a JSON data from it like as:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.webSpinner startAnimating];
NSURL * url=[NSURL URLWithString:[NSString stringWithFormat:@"http://www.janvajevu.com/webservice/specific_post.php?post_id=2885"]];
dispatch_async(kBgQueue, ^{
data = [NSData dataWithContentsOfURL: url];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
-(void)fetchedData:(NSData *)responsedata
{
if (responsedata.length > 0)
{
NSError* error;
self.webDictionary= [NSJSONSerialization JSONObjectWithData:responsedata options:kNilOptions error:&error];
self.webArray=[_webDictionary objectForKey:@"data"];
}
self.headingString=[self.webArray valueForKey:@"post_title"];
NSLog(@"Web String %@",self.headingString);
[self.webSpinner stopAnimating];
self.webSpinner.hidesWhenStopped=TRUE;
NSString *headingString=[NSString stringWithFormat:@"%@",self.headingString];
NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"() \n\""];
self.headLabel.text=[headingString stringByTrimmingCharactersInSet:charsToTrim];
}
Then I got a response like as means I got label text as:
"\U0aaa\U0abe\U0a97\U0ab2 \U0aae\U0abe\U0ab8\U0acd\U0aa4\U0ab0"
And when I parsed English letters from like as here in my URL "author_name"
contain English letters when I parsed it then it print as same as in JSON data but other language means here my URL other data contain Gujarati letters then it is parsed in to decoded or not in Gujarati letters.
Here I not encoded my URL in my code then how it come in this format? Please give me solution for it.
Upvotes: 0
Views: 97
Reputation: 561
try this
NSString *aDescription = self.webArray[0][@"post_title_slug"];
NSString *aTitle = [[aDescription stringByRemovingPercentEncoding] stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
Upvotes: 0
Reputation: 9285
You need to convert ASCII(Unicode Escaped) to Unicode(UTF-8).
check this : http://www.rapidmonkey.com/unicodeconverter/reverse.jsp
In first text box put your \U0aaa... text and click convert you will get what you want.
Now how you can do this in Objective-C: Try this and let me know what you get.
NSData *data = [self dataUsingEncoding:[NSString defaultCStringEncoding]];
NSString *unicodeString = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding];
self.headLabel.text = asciiString;
Upvotes: 1