开发者

TouchJSON Decoding Issue

I am trying to decode a JSON into an NSDictionary with many string pairs. Some of the returned strings return as &开发者_Python百科amp; instead of & and some of the non English characters appear as their url encoded value instead of their correctly decoded value. How can I fix this?

NSString *strContent = [[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding: NSUTF8StringEncoding];

//I cache the string here

NSData *jsonData = [strContent dataUsingEncoding:NSUTF8StringEncoding];
NSError *error = nil;
NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];


It's the payload as it arrives. You have to handle this after creation of the dictionary. You could do this just in time, when you need to work with the data or traverse the dictionary ahead of time and do some work to transform the data to the desired format.

The following NSString method may come in handy for unescaping url encoding: stringByReplacingPercentEscapesUsingEncoding

To unescape html entities have a look at this "objective-c-html-escape-unescape", it provides a clean way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜