JSON文字列を解析しようとしています:
array(3) {
["result"]=>
string(7) "success"
["source"]=>
string(12) "setWorldTime"
["success"]=>
bool(true)
}
このコードで:
SBJsonParser *parser = [[SBJsonParser alloc] init];
// Prepare URL request to download statuses from Twitter
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost/con.php?m=setWorldTime&a=London,0"]];
// Perform request and get JSON back as a NSData object
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
// Get JSON as a NSString from NSData response
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSLog(json_string);
// parse the JSON response into an object
// Here we're using NSArray since we're parsing an array of JSON status objects
NSDictionary *statuses = [parser objectWithString:json_string error:nil];
NSLog(@"OK: %@", [[statuses objectForKey:@"array"] objectForKey:@"result"]);
ただし、「OK: 成功」を出力する代わりに、「OK: (null)」を出力します。PHP スクリプトが必要な場合は、投稿できます。