Skip to content

What is the sorting basis for key values after decode? #95

Open
@NoWait126

Description

@NoWait126

Here is the content of json file

{
    "1": "1",
    "2": "2",
    "3": "3",
    "4": "4"
}

here is my code

local cjson = require "cjson"
local function load_file(user_conf_file)
    local f = io.open(user_conf_file)
    if not f then
      return nil
    end
    local cont = f:read("*a")
    f:close()
    local fjson = cjson.decode(cont)
    for k, v in pairs(fjson) do
      print(k)
    end
    return true
end

The output order is different each time,such as1432, 3142 .
So what is the sorting basis for key values after decode? Is there a way to guarantee the original order?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions