GithubHelp home page GithubHelp logo

shawvi / lua_parson Goto Github PK

View Code? Open in Web Editor NEW

This project forked from changnet/lua_parson

0.0 1.0 0.0 36 KB

a lua json encode/decode c module base on parson

Makefile 5.59% C 83.67% Lua 10.74%

lua_parson's Introduction

lua_parson

Build Status

A lua json encode/decode c module base on parson.
See more about parson at https://github.com/kgabis/parson

Installation

  • Make sure lua develop environment already installed
  • git clone https://github.com/changnet/lua_parson.git
  • cd lua_parson
  • git submodule update --init --recursive
  • make
  • make test
  • Copy lua_parson.so to your lua project's c module directory or link against liblua_parsion.a

Api

encode( tb,pretty )
encode_to_file( tb,file,pretty )

decode( str )
decode_from_file( file )

Array Object

  • If a table has only integer key,we consider it an array.otherwise is's an object.
  • If a table's metatable has field '__array' and it's value is true,consider the table an array
  • If a table's metatable has field '__array' and it's value is false,consider the table an object
  • Empty table is an object

Note:

  • If a array has illeage index(string or number key),it's key will be replace with index 1..n when encode
  • A sparse array will be filled with 'null' when encode

Example

See 'test.lua'

{"empty_object":{},"employees":[{"firstName":"Bill","lastName":"Gates"},{"firstName":"George","lastName":"Bush"},{"firstName":"Thomas","lastName":"Carter"}],"force_object":{"1":"USA","2":"UK","3":"CH"},"force_array":["987654321","123456789"],"sparse":[null,null,null,null,null,null,null,null,null,"number ten"],"empty_array":[]}
{
    empty_object =
    {
    }
    employees =
    {
        [1] =
        {
            firstName = "Bill"
            lastName = "Gates"
        }
        [2] =
        {
            firstName = "George"
            lastName = "Bush"
        }
        [3] =
        {
            firstName = "Thomas"
            lastName = "Carter"
        }
    }
    empty_array =
    {
    }
    force_array =
    {
        [1] = 987654321
        [2] = 123456789
    }
    sparse =
    {
        [10] = "number ten"
    }
    force_object =
    {
        ["3"] = "CH"
        ["2"] = "UK"
        ["1"] = "USA"
    }
}

lua_parson's People

Contributors

changnet avatar

Watchers

James Cloos 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.