私のアプリでは、次の方法でJSONを使用してデータをアップロードします。
NSMutableDictionary *titles = [NSMutableDictionary dictionary];
for (UITextField *textField in messagename)
{
[titles setObject: textField.text forKey: @"title"];
// as you can see, here you're replacing the value @ at key "title" with a new object on every pass
}
NSMutableDictionary *message = [NSMutableDictionary dictionary];
for (UITextField *textField in messagetext)
{
[message setObject: textField.text forKey: @"title"];
// as you can see, here you're replacing the value @ at key "title" with a new object on every pass
}
NSMutableDictionary *all = [NSMutableDictionary dictionary];
for (UITextField *textField in messagename)
{
[all setObject: titles forKey: message];
// as you can see, here you're replacing the value @ at key "title" with a new object on every pass
}
NSString *jsonString = [all JSONRepresentation];
NSData *jsonData = [jsonString dataUsingEncoding: NSUTF8StringEncoding];
[jsonData writeToFile: getImagePath atomically: YES];
NSString *destDir = @"/sandbox/";
[[self restClient] uploadFile:filename toPath:destDir
withParentRev:nil fromPath:getImagePath];
唯一の問題は、最後に作成されたテーブルのテキストのみがアップロードされ、すべてがアップロードされないことです。ケース付きのタグを使用しましたが、長すぎて、オブジェクトがnilの場合、アプリがクラッシュしました。また、「メッセージ」または「メッセージ名」を個別にアップロードすることしかできず、次の結果になります。
{"title":"Untitledjjjj"}
「すべて」の全体的な目的は、次のようなものにすることでした:メッセージ1(メインキー)とキータイトルの下、対応するタイトル、およびメッセージと対応するメッセージ。次にmessage2..。
これどうやってするの??すべてアップロードすると、結果は{}になります