我的应用程序从我的 php Web 服务接收到一个 json 响应,其中包含一组数据。如果我在 web 服务中打印出数组,我会在我的应用程序中收到以下内容,看起来不错。
NSLog(@"data: %@", [[NSString alloc] initWithData:downloaddata encoding:NSASCIIStringEncoding]);
输出:
[0] => Array
(
[id] => 3
[title] => some title //MySQL varchar(60), utf8_unicode_ci
[description] => some description //MySQL text, utf8_unicode_ci
[type] => AUDIO //MySql enum
[created] => 2013-02-25 00:00:00
[edited] => 2013-02-25 00:00:00
[version] => 1
[courserooms_id] => 1
)
[1] => Array
(
[id] => 4
[title] => some other title
[description] => some other description
[type] => MOVIE
[created] => 2013-02-12 00:00:00
[edited] => 2013-02-14 00:00:00
[version] => 1
[courserooms_id] => 1
)
在 iOS 中,我使用 NSJSONSerialization 解析接收到的数据。
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:downloaddata
options:kNilOptions
error:&error];
NSLog(@"error: %@", [error localizedDescription]);
NSLog(@"json: %@", json);
}
输出:
在输出中,数组的字符串值为空,我不知道为什么。
{
"courserooms_id" = 1;
created = "2013-02-25 00:00:00";
description = "<null>";
edited = "2013-02-25 00:00:00";
id = 3;
title = "<null>";
type = AUDIO;
version = 1;
},
{
"courserooms_id" = 1;
created = "2013-02-12 00:00:00";
description = "<null>";
edited = "2013-02-14 00:00:00";
id = 4;
title = "<null>";
type = MOVIE;
version = 1;
}
我的 php webservice 返回内容类型:text/html; charset=utf-8 知道为什么字符串解析为 null 吗?
提前致谢!