When I try to read a json file and I use Json.Encode/Json.Decode (or json.encode/json.decode) my output is an valid json, with all attributes, but out of order. Example:
Code:
local f = io.open("|R|settings.json", "r")
local data = f:read("*all")
local json = Json.Decode(data)
f:close()
print(Json.Encode(json.user)) |
Input:
"user": {
"name": "",
"email": "",
"voucher": "",
"tickets": 1,
"facebookLike": false,
"wizardStudent": false,
"counter": {"acertadas": 0, "total": 200}
}
Output:
{"voucher":"","wizardStudent":false,"name":"","counter":{"acertadas":0,"total":200},"facebookLike":false,"tickets":1,"email":""}
Why this is important?
I need to generate an hash code (SHA1 + salt) with this data in App and server. If the order of the data is different, the SHA1 will never match. I have no idea what causes the disorder, apparently the code json.lua has nothing to do it.
@ar2rsawseen, have any idea??
Comments
you would need to create string from it yourself by combining components manually in specific order.
If you are using pairs, yes you will have an issue as the order the results are not sorted. If you have a long list that you need to use, then use a secondary table with the string keys which is indexed and iterate through this too get the values of the second. In case you are confused...
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
if the results that are returned are not pre-determined then you need to parse the same and sort the tables yourself and use it.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
i have a value stored as -139.89
and the value restored is -139.88999999999999
etc with most of the values i store like this (all have 2 precision digits like this one).
is this a bug in the json decoder?
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
https://deluxepixel.com
Fragmenter - animated loop machine and IKONOMIKON - the memory game
https://deluxepixel.com
Likes: SinisterSoft
Fragmenter - animated loop machine and IKONOMIKON - the memory game
https://github.com/gideros/gideros/issues/320
Likes: SinisterSoft
Fragmenter - animated loop machine and IKONOMIKON - the memory game