Code Monkey home page Code Monkey logo

cjson's Introduction

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)

cjson's People

Contributors

candymi avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.