开发者

data parse with json touch

I am using this example: http://tempered.mobi/sites/default/files/JSonArticle.zip

But it show null value at time parsing.

My PHP code output:

{"news":[{"title":"DurianFM Android Application"},{"title":"Hari Raya"},{"title":"C"}]}

iPhone code:

(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 . it's a big problem for me . NSData not convert into NSDictionary NSDictionary variable show null value.

please help .

I have solved this problem by change deserializeAsDictionary to deserialize


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜