Jupiters Posted March 1, 2021 Share Posted March 1, 2021 Recently, the new update made us able to rename a beefalo. When I renamed a beefalo as "Jupiter's Beefalo" tried to use "json.encode(beefalo:GetSaveRecord())" to get the string form of saving record, the string was like ".......Jupiter\'s Beefalo......", which seemed ok in lua enviroment in DST. However, when I tried to use this string in Python, I executed "json.loads(the_string)" and it went wrong because of the damn "\'s" in the string. The problem was caused by the mechanism that the JSON library of lua would change "'" into "\'" when encoding a string. Some may say that I can choose "json.encode_compatible()" function instead. But the note of DST official "json.lua" warned that we should never add decode support from encode_compliant's returned string. Since I wanted to encode data and send it to my backend server, and retrieved it and decode it to be used in game, I desperately need a JSON library implemented in C language to make it happen. Will that be possible? Link to comment Share on other sites More sharing options...
penguin0616 Posted March 1, 2021 Share Posted March 1, 2021 The warning to never add decode support is for decoding within the game. encode_compliant is meant to be read outside of the game. Otherwise, there wouldn't be a reason for it to exist. So go ahead and use it. Link to comment Share on other sites More sharing options...
Whateverr Posted March 2, 2021 Share Posted March 2, 2021 Klei uses json4Lua to convert between lua tables and json strings in DST. This library has many fatal flaws, which are presented on http://lua-users.org/wiki/JsonModules. I think you can use other json libraries implemented in pure lua to replace it if necessary. The alternatives I found are as follows. LunaJson https://github.com/grafi-tt/lunajson json.lua https://github.com/rxi/json.lua Link to comment Share on other sites More sharing options...
Chesmu Posted March 6, 2021 Share Posted March 6, 2021 Fun fact is, if you go to Careers page, you will see the only job Klei is hiring for right now is a C++ programmer! (The person getting hired will probably know all C languages, due to background requirement.) I'm sure they are aware of this problems and will fix it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.