iOS で HTTP リクエスト用の JSON 文字列を作成する方法
私はこれらの値を持っています:
{"name":"customer6","pass":"customer6", "mail":"customer6@xy.com","user_roles":"5", "field_login_pin_value":{"und":[{"value":"2324"}]} }
では、このデータから JSON 文字列を作成するにはどうすればよいでしょうか?
これが私のコードです:
NSArray *keys = [NSArray arrayWithObjects:@"name",@"pass",@"mail",@"user_roles",@"field_login_pin_value", nil];
NSArray *objects = [NSArray arrayWithObjects:@"customer6",@"customer6",@"customer6@xy.com",@"5",@"{\"und\":[{\"value\":\"2324\"}]", nil];
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSString *jsonString = [jsonDictionary JSONRepresentation];
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://xxxxxxxx/register.json"]];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:jsonString forHTTPHeaderField:@"json"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:jsonData];
nsconnection= [[NSURLConnection alloc] initWithRequest:request delegate:self];
Web サービス リクエストをヒットすると、次の応答が返されます。
"form_errors" = {
"field_login_pin_value][und][0][value" = "PIN value field is required.";
};
}
私はいつも同じエラーが発生します
誰かが私の実装の何が問題なのか教えてもらえますか?