Need a JSON library implemented in C language

Recommended Posts

Jupiters    4

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?

Edited by Jupiters

Share this post

Link to post
Share on other sites
penguin0616    932

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.

Edited by penguin0616
  • Like 1

Share this post

Link to post
Share on other sites
Flynn_    5

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.

  1.  LunaJson https://github.com/grafi-tt/lunajson
  2.  json.lua https://github.com/rxi/json.lua
Edited by Flynn_

Share this post

Link to post
Share on other sites
Chesmu    212

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. :)

Edited by Chesmu

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now