0

i have question about YAJLiOS parser... I have next json data :

   {{
    body = "Привет";
    mid = 3;
    "read_state" = 1;
   }
   { body = "hi";
     mid = 3;
     "read_state" = 1;
    }}

and i'm trying to get "body" , result is : "\U0416\U0412" and "hi"

it might be problem with encoding, but i have no idea how to fix it

Thanks for your time!

Vlad Z.
  • 3,401
  • 3
  • 32
  • 60
  • Can you show the code from where you are doing the parsing? – jonkroll Mar 29 '12 at 15:30
  • sure: NSString *getFriendDialogs = [NSString stringWithFormat:@"https://api.vk.com/method/messages.getHistory?access_token=%@&uid=%@&chat_id=uid&count=10",currentAccessToken,UidOfSelectedFriend]; NSURL *url = [NSURL URLWithString:getFriendDialogs]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; NSData *tempContainer = [NSURLConnection sendSynchronousRequest:requestObj returningResponse:nil error:nil]; NSDictionary *dialogsDictionary = [tempContainer yajl_JSON]; idString = [dialogsDictionary valueForKey:@"body"]; – Vlad Z. Mar 29 '12 at 15:34

1 Answers1

0

You may need to convert to a string first to deal with the UTF-8 character encoding.

NSData *tempContainer = [NSURLConnection sendSynchronousRequest:requestObj returningResponse:nil error:nil];

NSString *tempString = [NSString stringWithUTF8String:[tempContainer bytes]];

NSDictionary *dialogsDictionary = [tempString yajl_JSON];
jonkroll
  • 15,682
  • 4
  • 50
  • 43
  • is there other character encoding that i can use? – Vlad Z. Mar 30 '12 at 11:21
  • NSData tempContainer = [NSURLConnection sendSynchronousRequest:requestObj returningResponse:nil error:nil]; NSString content = [[NSString alloc] initWithData:tempContainer encoding:NSUTF8StringEncoding]; all is ok when i use this code,but need nsdictionary not nsstring – Vlad Z. Mar 30 '12 at 20:42