在我的应用程序中,我通过以下方式使用 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];
唯一的问题是只上传了最后创建的表格的文本,而不是全部。我将标签与案例一起使用,但它太长了,如果一个对象为零,应用程序就会崩溃。另外,我只能用这个结果单独上传“消息”或“消息名称”:
{"title":"Untitledjjjj"}
“all”的全部目的是有类似的东西:message1(主键)带有下键标题,带有相应的标题,以及带有相应消息的消息。然后消息2...
我怎样才能做到这一点??如果我上传所有结果是 {}