nslog阅览出来未显示中文 想请教一下原因
xcode吧
全部回复
仅看楼主
level 6
洋芋逛逛 楼主
- (void)viewDidLoad {
[super viewDidLoad];
[self getweather];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)getweather{
NSURL *url = [NSURL URLWithString: @"http://wthrcdn.etouch.cn/weather_mini?citykey=101010100"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req addValue:@"text/html; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req setHTTPMethod:@"GET"];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn)
{
webData = [NSMutableData data];
}
}
-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *) response
{
[webData setLength: 0];
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *) data
{
[webData appendData:data];
}
-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *) error
{
conn = nil;
webData = nil;
}
-(void) connectionDidFinishLoading:(NSURLConnection *) connection
{
id json = [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
NSLog(@"%@",json);
}
以上是代码
下面是数据在控制台的显示情况
data = {
aqi = 67;
city = "\U5317\U4eac";
forecast = (
{
date = "26\U65e5\U661f\U671f\U4e00";
fengli = "3-4\U7ea7";
fengxiang = "\U5317\U98ce";
high = "\U9ad8\U6e29 15\U2103";
low = "\U4f4e\U6e29 6\U2103";
type = "\U9634";
},
{
date = "27\U65e5\U661f\U671f\U4e8c";
fengli = "\U5fae\U98ce\U7ea7";
fengxiang = "\U65e0\U6301\U7eed\U98ce\U5411";
high = "\U9ad8\U6e29 17\U2103";
low = "\U4f4e\U6e29 4\U2103";
type = "\U6674";
},
有木有大脚来帮我解释一下
2015年10月26日 12点10分 1
level 9
正常,字典中的中文输出是这样的了,想解决要么一个个输出,要么用运行时替换自定义的NSLog
2015年10月26日 13点10分 2
也就是说我的解析和转码都是对的?我可以直接用数据了?
2015年11月01日 02点11分
1