我得到我的JSON一個使用未聲明的標識符錯誤的,但我下面從http://blog.zachwaugh.com/post/309924609/how-to-use-json-in-cocoaobjective-c使用未聲明的標識符的JSON的iOS
我怎麼解決這個問題的例子嗎?是的,我是很新的Objective-C的\ IOS :)謝謝
我把在我看來,基於應用程序的代碼在我viewcontroller.m文件
的問題是與「SBJSON *解析器= [[SBJSON alloc] init];「
// Create new SBJSON parser object
SBJSON *parser = [[SBJSON alloc] init];
// Prepare URL request to download statuses from Twitter
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://twitter.com/statuses/public_timeline.json"]];
// 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];
// parse the JSON response into an object
// Here we're using NSArray since we're parsing an array of JSON status objects
NSArray *statuses = [parser objectWithString:json_string error:nil];
// Each element in statuses is a single status
// represented as a NSDictionary
for (NSDictionary *status in statuses)
{
// You can retrieve individual values using objectForKey on the status NSDictionary
// This will print the tweet and username to the console
NSLog(@"%@ - %@", [status objectForKey:@"text"], [[status objectForKey:@"user"] objectForKey:@"screen_name"]);
}
你有沒有想起導入SBJSON庫? – Circumflex
是的。我添加了來自classes文件夾和#import SBJson.h的所有文件。所以不知道發生了什麼。 – Rick