Saturday, November 30, 2013

json data containing Chinese, parsing always a null value, seek expert education

NSURL * url = [NSURL URLWithString: @ "http://www.cnliuda.com/API/index1_hot.asp"];
ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL: url];

[Request setDelegate: self];
[Request startAsynchronous];


- (Void) requestFinished: (ASIHTTPRequest *) request
{

NSString * responseString = [request responseString]; / / For binary data, use: NSData * responseData = [request responseData];
NSLog (@ "% @", responseString);

arrayData = [NSJSONSerialization JSONObjectWithData: [responseString dataUsingEncoding: NSUTF8StringEncoding] options: NSJSONReadingMutableLeaves error: nil];
NSLog (@ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!! ");
NSLog (@ "arrayData =% @", [arrayData description]);

}
/ / Request fails, get error
- (Void) requestFailed: (ASIHTTPRequest *) request
{
NSError * error = [request error];
NSLog (@ "% @", error userInfo.);
}
Then been output arrayData = nil, "itemName" on the page: "fringed vest doll dress ~", "itemDesc": "This is a great upper body, the fabric is very comfortable, white color, skin effect is often gray lining Ay ~ "print out" itemName ":" 流 苏 背 心 娃 娃 裙 ~ ", "itemDesc": "这 一 款 上 身 效 果 极 佳 , 面 料 也 很 舒 服 , 纯 白 的 颜 色 , 衬 肤 效 果 灰 常 好 哦 ~ ", has not found a solution, ask God to help large
Reply:
Web client data released is UTF-8 encoding it?
Reply:
In other postings have replied, tried not?


http://www.cnliuda.com/API/index1_hot.asp This is used for encoding
UTF-8
Although the normal browser can parse into Chinese, but you see through the browser source code found, in fact, and you get to the data is the same solution:
http://www.cnliuda.com/API/index1_hot.asp to GB2312 code output

Or:

1, NSString * responseString = [request responseString]; instead
NSData * responseData = [nsstring dataUsingEncoding: -2147482063];

2, in the back of an increase in the following statement
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingGB_18030_2000);
NSString * responseString = [[NSString alloc] initWithData: responseData encoding: enc];
Reply:
The reply was deleted at the moderator 2012-08-09 08:37:18

No comments:

Post a Comment