diff options
| author | ruki <[email protected]> | 2024-07-02 23:39:27 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-07-02 23:39:27 +0800 |
| commit | 35ec8577f2d81e472a8bc0db9ce66215f3182b4f (patch) | |
| tree | 2af18da63bc936cb8820b64053d71f6adcdc908a /xmake/core/base/json.lua | |
| parent | 59327827e900ee5b61abba74e85d6081933d2a5a (diff) | |
add pure json test
Diffstat (limited to 'xmake/core/base/json.lua')
| -rw-r--r-- | xmake/core/base/json.lua | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/xmake/core/base/json.lua b/xmake/core/base/json.lua index 4c619e69a..bf1dfae3e 100644 --- a/xmake/core/base/json.lua +++ b/xmake/core/base/json.lua @@ -256,7 +256,11 @@ end -- @return the lua table -- function json.decode(jsonstr, opt) - local ok, luatable_or_errors = utils.trycall(cjson and cjson.decode or json._pure_decode, nil, jsonstr) + local decode = cjson and cjson.decode or json._pure_decode + if opt and opt.pure then + decode = json._pure_decode + end + local ok, luatable_or_errors = utils.trycall(decode, nil, jsonstr) if not ok then return nil, string.format("decode json failed, %s", luatable_or_errors) end @@ -271,7 +275,11 @@ end -- @return the json string -- function json.encode(luatable, opt) - local ok, jsonstr_or_errors = utils.trycall(cjson and cjson.encode or json._pure_encode, nil, luatable) + local encode = cjson and cjson.encode or json._pure_encode + if opt and opt.pure then + encode = json._pure_encode + end + local ok, jsonstr_or_errors = utils.trycall(encode, nil, luatable) if not ok then return nil, string.format("encode json failed, %s", jsonstr_or_errors) end |
