JSON 解析を使用して、php を使用して MySql からデータを取得しています。必要なすべてのデータを取得しましたが、このデータを印刷したいときに for ループを作成しましたが、最後の要素のみが得られます..これは私のコードです
DidViewLoad で:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *phpUrl = @"http://dt-works.com/eman/bookOwn.php";
NSString *dbName = @"dbName";
NSString *localHost = @"localhost";
NSString *dbUser = @"dbUser";
NSString *dbPwd = @"dbPwd";
int u_id = 1;
NSString *user_id = [NSString stringWithFormat:@"%d",u_id];
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:phpUrl]];
[request setHTTPMethod:@"POST"];
NSString *post = [[NSString alloc] initWithFormat:@"dbName=%@&localHost=%@&dbUser=%@&dbPwd=%@&user_id=%@&submit=", dbName, localHost, dbUser, dbPwd, user_id];
[request setHTTPBody:[post dataUsingEncoding:NSUTF8StringEncoding]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSArray *statuses = [parser objectWithString:json_string error:nil];
int arraySize = [statuses count];
for (NSDictionary *status in statuses)
{
bo_id2 = [status objectForKey:@"bo_id"];
bo_name2 = [status objectForKey:@"bo_name"];
bo_au_id2 = [status objectForKey:@"bo_au_id"];
bo_pub_id2 = [status objectForKey:@"bo_pub_id"];
bo_num_pages2 = [status objectForKey:@"bo_num_pages"];
bo_publish_year2 = [status objectForKey:@"bo_publish_year"];
}
NSLog(@"size of array is: %d", arraySize);
for (int i=0; i<arraySize; i++) {
NSLog(@"%d:",i);
// here I want to retrieve all array elements .. when I try
NSLog(@"Book id: %@ - book name: %@", bookId, bookName);
// this give me the last elemet only not all data
// I want to get the data here to use it later .. how ???
}
}
何か助けて??