Notes when using JsonKit to parse Chinese characters.

Source: Internet
Author: User

Notes when using JsonKit to parse Chinese characters.

If the return value is null when parsing Chinese characters using JsonKit, it may be caused by inaccurate length calculation.

Solution:

NSString * pricePath = [[NSBundle mainBundle] pathForResource: @ "CarSelectPrice" ofType: @ "json"]; NSString * priceStr = [[NSString alloc] Protocol: pricePath encoding: publish error: nil]; NSLog (@ "% @", priceStr); // calculates the length of a Chinese string, if the returned value is null. It is very likely that this value is incorrect. NSInteger length = [[priceStr dataUsingEncoding: descriallowlossyconversion: YES] length]; _ allPriceArr = [NSMutableArray array]; _ allCarTypeArr = [NSMutableArray array]; NSArray * tmpJson = [jsonDecoder objectWithUTF8String :( const unsigned char *) [priceStr UTF8String] length :( unsigned int) length]; NSLog (@ "priceArr = % @", _ allPriceArr );


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.