Backendless Support
 
Waiting for user's response

Problem saving JSON file in ios

I need to save an NSDictionary in Backendless. Because there is no support for saving such a piece of data (or an array), I am attempting to convert the NSDictionary to NSData using JSON Serialization then save the NSDate to a json file in Backendless. There is no trouble until that last part. I cannot successfully save the .json file to Backendless.

My code is as follows:

  1. NSString *convoStatusDictName = [NSString stringWithFormat:@"%@-ConvoStatusDict.json", currentUser.objectId];
  2. NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"testObject", @"testKey", nil];
  3. NSError *error = nil;
  4. NSData* jsonData = [NSJSONSerialization dict options:NSJSONWritingPrettyPrinted error:&error];
  5. [backendless.fileService upload:convoStatusDictName content:jsonData response:^(BackendlessFile *convoStatusDictFile)
  6. {
  7. // blah blah blah
  8. } error:^(Fault *fault) {

    NSLog(@"fault saving convos file: %@", fault);

    }];

This is causing the following error:

Server reported an error (ASYNC): FAULT = '1007' [Unable to save object - invalid data type for properties - convoStatusDict. You can change the property type in developer console.] <Unable to save object - invalid data type for properties - convoStatusDict. You can change the property type in developer console.>

I have no problem saving a .jpeg file, but this is clearly different and is not working. Thanks!

Leave a Comment

Comments (4)

photo
1

Hi Cooper,

We are testing now a new MapDrivenDataStore class, it will allow to save/retrieve/delete a dictionary.

We plan to release a new Backendless SDK version next week, maybe you could wait it?

Regards,

Slava

photo
1

BTW: now you are able to save/update a dictionary with these methods of PersistenceService class.

photo
1

I need to save the NSDictionary as a property in the user class. Which of those two solutions allow me to do that?

Also, could you please show me where I am going wrong in saving that file for future reference? Is there an example project or something that demonstrates how to save a file?

Thanks!

photo
1

No, Cooper - you wouldn't be able to save NSDictionary as user property, but you could create a class with properties named as your dictionary keys, and use one-to-one or one-to-many relation to save the objects of this class in user property. Please, see this doc. You could also investigate this sample project from our BlogFeatureDay examples.

About file saving - see our sample project. Also you could investigate the FileService demo project in our iOS-Samples github. And this is a doc about FileService.

Regards,

Slava

photo