mySQLにNSArrayをInsertしたく、
lang
1NSData* data = [NSKeyedArchiver archivedDataWithRootObject:array];
でバイナリデータに変換し、
lang
1NSString* post = [NSString stringWithFormat:@"http://localhost/test.php&array=%@",array]; 2NSData* data = [post dataUsingEncoding:NSUTF8StringEncoding]; 3NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init]; 4[request setURL:url]; 5[request setHTTPMethod:@"POST"]; 6[request setHTTPBody:data];
でPOST送信を行いました。対象カラムのデータ型はBLOB型です。
取得時は以下の様に実装し、データの取得までは確認が取れています。
lang
1NSString* url = [NSString stringWithFormat:@"http://localhost/load.php"]; 2// NSURLからNSURLRequest 3NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; 4// サーバーとの通信を行う(URLRequest) 5NSData* json = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 6NSArray *array = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingAllowFragments error:nil]; 7//1件目のデータだけで検証しています 8NSDictionary* dic = [[NSDictionary alloc] initWithDictionary:(NSDictionary *)array[0]]; 9 10NSArray* ary = [NSKeyedUnarchiver unarchiveObjectWithData:(NSData *)dic[@"array"]];//①
①の場所で-[__NSCFString bytes]: unrecognized selector sent to instance 0x7fdabb8170e0となり落ちてしまいます。
NSLogでdic[@"array"]のバイナリデータのログを出力したところ、POST送信前のバイナリデータと一致したのでINSERTからデータ取得まではできています。
しかしUnachrveだけがうまくいきません。どなたかご教授お願いいたします。
ちなみにデータ取得のPHPソースコードは、
lang
1<?php 2 3require_once('conf.php'); 4require_once('functions.php'); 5 6$sql = 'SELECT * FROM test'; 7 8header('Content-type: application/json'); 9echo json_encode(connectDatabase()->query($sql)->fetchAll(PDO::FETCH_ASSOC)); 10 11?>
です。
あなたの回答
tips
プレビュー