2012-03-29 55 views
0

我有問題有關YAJLiOS解析器...... 我有下一個JSON數據:YAJLiOS無法解析非英文字母?

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

,我試圖讓「身體」,結果是:「\ U0416 \ U0412」和「喜」

它可能是與編碼的問題,但我不知道如何解決它

感謝您的時間!

+0

你可以顯示你正在做解析的代碼嗎? – jonkroll 2012-03-29 15:30:02

+0

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」]; – ignotusverum 2012-03-29 15:34:01

回答

0

您可能需要先轉換爲字符串來處理UTF-8字符編碼。

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

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

NSDictionary *dialogsDictionary = [tempString yajl_JSON]; 
+0

謝謝,但這並沒有幫助;( – ignotusverum 2012-03-29 19:40:03

+0

是否還有其他字符編碼,我可以使用? – ignotusverum 2012-03-30 11:21:01

+0

NSData tempContainer = [NSURLConnection sendSynchronousRequest:requestObj returningResponse:nil error:nil]; NSString content = [[NSString alloc] initWithData:tempContainer encoding: NSUTF8StringEncoding];當我使用這段代碼時一切正常,但需要nsdictionary而不是nsstring – ignotusverum 2012-03-30 20:42:39