Is it possible to serialize a ValueMap to a String and unserialize it later?

Is it possible to serialize a ValueMap to a String and unserialize it later?

I need to populate a ValueMap from data stored on a server, so it would be great to be able to serialize the data and unserialize it later.

Should I use xml for this? plist ?

I will use JSON and then create the valuemap with a custom method.

You should look into these methods:

ValueMap FileUtils::getValueMapFromFile(const std::string& filename) {return ValueMap();}
ValueMap FileUtils::getValueMapFromData(const char* filedata, int filesize) {return ValueMap();}
ValueVector FileUtils::getValueVectorFromFile(const std::string& filename) {return ValueVector();}
bool FileUtils::writeToFile(const ValueMap& dict, const std::string &fullPath) {return false;}

Thanks! I will take a look at those methods.
So we have a method to save a valuemap to string or char instead of a plist file?

I notice that cocos use tinyxml to save a valuemap to a file, maybe we can use the same and return a char with the content of the valuemap so we can use it for whatever we want.

With FileUtils::writeToFile you can save a ValueMap as a plist file (basically a particular XML file) in persistent storage specifying a full path (take a look to string FileUtils::getWritablePath()).
When you want to get back your ValueMap from the plist you call FileUtils::getValueMapFromFile

This Method is fine, but I think we are missing a method like this

std::string FileUtils::getStringFromValueMap(const ValueMap& dict);

Or char* or something like that.

I just wanted to say that it’s probably pretty straightforward to make a method like that with the help of a json library, but since I also need the exact same functionality in my game I decided to make it myself: https://github.com/domp/CCSerialization