In my app I upload data using JSON in the following way:
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];
the only problem is that only the text for the last created table is uploaded, not all. I used the tags with cases, but it was too long , and If an object was nil, the app crashed.
Also, I can only upload “message”, or “message name” separately with this result:
{"title":"Untitledjjjj"}
The whole purpose of the “all” was to have something like: message1 (main key) with under key title, with corresponding title, and message with corresponding message. then message2…
How can I do this?? If I upload all the result is {}
You are using the same key all the time.. probably you should use an array instead for both
titlesandmessage.I will just fix the first part, that should be enough:
Do you get it? In a dictionary, one key can only have one value. So you are always replacing the contents with each call of
[dicitonary setObject: ... forKey: @"title"];