JSON编码UTF-8字符串

时间:2015-04-18 16:16:15

标签: ios objective-c xcode utf-8

如何从网址获取JSON并将NSString编码为使用NSLog显示? JSON包含中文单词。

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

[request setURL:[NSURL URLWithString:@"http://jxdp.mnks.cn/read.php?xCode=6beff&Code=6beff&Type=1&&top=5&min=0&CALL="]];
[request setHTTPMethod:@"GET"];

NSURLResponse *requestResponse;
NSData *requestHandler = [NSURLConnection sendSynchronousRequest:request returningResponse:&requestResponse error:nil];

NSString *requestReply = [[NSString alloc] initWithBytes:[requestHandler bytes] length:[requestHandler length] encoding:NSUTF8StringEncoding];

NSLog(@"requestReply: %@", requestReply);

0 个答案:

没有答案