objective c - more specific about sending json with utf8 to iphone from php server -
we have php server sends json string in utf-8 encoding. im responsible iphone app data.
i want sure on side correct :
//after downlad data stream : nsstring* content = [[nsstring alloc] initwithdata:self.m_datatoparse encoding:nsutf8stringencoding]; //here data shown correctly in console nslog(@"%@",content); sbjsonparser *_parser = [[sbjsonparser alloc]init]; nsdictionary *jsoncontentdictionary = [_parser objectwithdata:self.m_datatoparse]; //here, when printer values of array in array, see \u454 u\545 \4545 format. ideas why ? for(id key in jsoncontentdictionary) { nslog(@"key:%@, value:%@,key, [ jsoncontentdictionary objectforkey:key]); }
im using latest version of json library : https://github.com/stig/json-framework/
there problem iphone side ? (json parser ? ) or in php server ?
just clear again : 1.on console, before json, string looks o.k 2.after doing json, array in array values in format of \u545 \u453 \u545
thanks in advance.
your code correct. possible reason of issue, , must investigate content provider (the server sends json you), if whole json string correctly encoded utf-8 (remember: json text sequence of character , encoding must specified), may happen or of text content (that values of single objects contained in json message) has been encoded in format, typically html-encoding (iso-8859) when particular characters used (e.g. cyrillic or asian). json framework default decodes data utf-8, if there coding mismatch between utf-8 characters , iso-8859 (just remain in example) way transform them in utf-8 use \u format. happens quite often, when php scripts extract info html pages, encoded using iso-8859. , consider ios not able convert whole set of iso-8859 characters unicode (e.g.: cyrillic). possible solutions are: - content encoding of texts server side (iso-8859 --> utf-8) - or if not possible, it's recognize \uxxx sequences coming more content provider , replace them corresponding utf-8 characters.
Comments
Post a Comment