How to decode UTF8 characters using JSON on iPhone?

I use the ASIHTTP request to get the NSString response that I pass to the SBJSON block.

The problem is that inside the NSString answer, I got some UTF8 encoded character (accent), which I need to do to decode for the application to work.

How can I decode UTF8 using JSON?

I call the JSON message as follows:

[jsonParser objectWithString:jsonString error:NULL];

Any help would be so appreciated.

Fabrizio

+3
source share
2 answers

lol .... Great! but for the sake of simplicity I will say.

Create a new SBJSON parser object

SBJSON *parser = [[SBJSON alloc] init];

Prepare a URL request to download statuses from Twitter

NSURLRequest *request = [NSURLRequest requestWithURL:
    [NSURL URLWithString:@"http://twitter.com/statuses/public_timeline.json"]];

Run the request and return JSON as an NSData object p>

NSData *response = [NSURLConnection sendSynchronousRequest:request 
    returningResponse:nil error:nil];

JSON NSString NSData​​p >

NSString *json_string = [[NSString alloc] 
    initWithData:response encoding:NSUTF8StringEncoding];

JSON NSArray, JSON

NSArray *statuses = [parser objectWithString:json_string error:nil]

.

+4

, , .

Thanx .

+2

Source: https://habr.com/ru/post/1748980/


All Articles