Skip to content
/ cjson Public

JSON library written using Lua 5.3+ C API.

License

Notifications You must be signed in to change notification settings

CandyMi/cjson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cjson

JSON library written using Lua 5.3+ C API.

Install

  1. clone to 3rd.

  2. make build

  3. Done.

Defined

local ljson = require "ljson"
local ljson_encode = ljson.encode
local ljson_decode = ljson.decode

local type = type

local json = { }

---comment 空数组
json.empty_array = ljson.empty_array

---comment @将`table`序列化为`json`格式的`string`.
---@param tab    table     @可序列化为`json`类型的`table`.
---@param prefix table?    @`jsonp`前缀.
---@return string          @成功返回`json`格式的`string`, 失败会抛出异常.
function json.encode(tab, prefix)
  return ljson_encode(tab, type(prefix) == 'string', prefix)
end

---comment @将`json`格式的`string`解析为`table`
---@param buffer string    @`json`格式的`string`.
---@param jsonp  boolean?  @会尝试检查`jsonp`结构.
---@return table | false   @成功返回`table`, 失败返回`nil``errinfo`.
---@return string?         @成功返回`table`, 失败返回`nil`与`errinfo`.
function json.decode(buffer, jsonp)
  return ljson_decode(buffer, jsonp and true or false)
end

return json

Usage

  local json = require "ljson"
  -- json.encode ( table )
  
  -- json.decode (json string)

About

JSON library written using Lua 5.3+ C API.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published