[英]data parse with json touch
I am using this example: http://tempered.mobi/sites/default/files/JSonArticle.zip 我正在使用以下示例: http : //tempered.mobi/sites/default/files/JSonArticle.zip
But it show null value at time parsing. 但它在解析时显示空值。
My PHP code output: 我的PHP代码输出:
{"news":[{"title":"DurianFM Android Application"},{"title":"Hari Raya"},{"title":"C"}]}
iPhone code: iPhone代码:
(void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://...........jsontest.php"];
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url];
NSLog(jsonreturn); // Look at the console and you can see what the restults are
NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;
// In "real" code you should surround this with try and catch
NSDictionary * dict = [[[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error] retain];
if (dict)
{
rows = [dict objectForKey:@"news"];
}
NSLog(@"Array: %@",rows);
[jsonreturn release];
}
when I check dict variable it always show null value . 当我检查dict变量时,它总是显示null值。 it's a big problem for me . 对我来说这是一个大问题。 NSData not convert into NSDictionary NSDictionary variable show null value. NSData无法转换为NSDictionary NSDictionary变量显示为空值。
please help . 请帮忙 。
I have solved this problem by change deserializeAsDictionary to deserialize 我已经通过将deserializeAsDictionary更改为反序列化来解决了这个问题
you have to change tag. 您必须更改标签。
rows = [dict objectForKey:@"news"];
EDIT 编辑
NSURL *url = [NSURL URLWithString:@"http://...........jsontest.php"];
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url];
NSDictionary *results = [jsonreturn JSONValue];
Try this one it works for me. 试试这个对我有用的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.