私はJSON解析を使用してPHPを使用してMySqlからデータを取得しています 私が望むすべてのデータがありますが、このデータを印刷したいときはforループを作成しましたが、のみ。これはDidViewLoadで私のコードnsarrayの全データを取得
です:
- (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 ???
}
}
任意のヘルプ?
ループ内に変数を印刷しています。毎回同じ値が印刷されます。これは必要なサポートを必要とする質問ではありません。 – rakeshNS