1

I'm trying to load this JSON:

{ Name: "Hebrew String",
Image: "", Category: "Hebrew String",
Ingredients: "Hebrew String",
Price: "300" },.......

My code:

 NSURL *url = [[NSURL alloc] initWithString:@"url"];
 NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

 AFJSONRequestOperation *operation = [AFJSONRequestOperation
 JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {

 NSLog(@"json = %@",JSON);       
 [[NSNotificationCenter defaultCenter]
                 addObserver:self
                 selector:@selector(dataretrived)
                 name:@"JsonFinishLoading"
                 object:nil];


 }failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {}

The dta coms out scramble:

Category = "\U05db\U05e8\U05d9\U05da \U05d8\U05d5\U05e0\U05d4";  
        Image = "";  
        Ingredients = "\U05d8\U05d5\U05e0\U05d4,\U05e2\U05d2\U05d1\U05e0\U05d9\U05d4";  
        Name = "\U05db\U05e8\U05d9\U05da \U05d8\U05d5\U05e0\U05d4";  
        Price = 300;
    }....

How can I convert the data so it displays properly?

Unheilig
  • 16,196
  • 193
  • 68
  • 98
Bar
  • 603
  • 1
  • 7
  • 19
  • 1
    The data is just fine. It logs like that because NSLog doesn't know how to display multi-byte characters. – Hot Licks Dec 31 '13 at 17:17
  • (And wasn't almost the exact same question asked here yesterday?) – Hot Licks Dec 31 '13 at 17:19
  • i didn't find the post can you post the link , – Bar Dec 31 '13 at 17:46
  • when i'm trying to show in table view is don't show so the data is not fine. – Bar Dec 31 '13 at 17:47
  • The first character above is the [Hebrew letter "kaf"](http://www.utf8-chartable.de/unicode-utf8-table.pl?start=1280). I'm pretty sure they're all OK. – Hot Licks Dec 31 '13 at 18:19
  • You say above that the JSON string you have (after reception?) contains the Hebrew characters. If they're not making it into the parsed JSON you're using the wrong parser or have the wrong settings -- a proper JSON parser, in default mode, should leave UTF-encoded strings unmodified. (Of course, it *is* possible that the JSON is getting garbled in transmission, if the wrong options are chosen there. But you imply that the received JSON is OK.) – Hot Licks Dec 31 '13 at 20:15

1 Answers1

0

I am guessing that the JSON string has the ASCII character '\' followed by 'U' followed by '0' followed by '5' etc. You will need to convert the substring \U05db to the unichar 0x05db and then do that for each \UXXXX. I work with Hebrew in Xcode a lot and when I do an NSLog for strings that contain Hebrew it prints to the console just fine.

Stephen Johnson
  • 5,293
  • 1
  • 23
  • 37