json.encode

将表格数据编码为 JSON 字符串。

格式:

jsonString = json.encode(表格对象)
用法示例: local str = json.encode({a=,b="ss",c={c1=,c2=},d={,},})
echo(str) -- {"a":1,"b":"ss","c":{"c1":1,"c2":2},"d":[10,11],"1":100}
local str = json.encode({,,"",{,}})
echo(str) -- [1,2,"3",[10,11]]
Note: table作为字典使用时,整型键值将被转换为字符串键值 local str = json.encode({a=,[]=})
echo(str) -- {"a":1,"5":3}
Note: table所有键值为整型时,会当作数组看待,空位将转化为null local str = json.encode({[]=,[]=})
echo(str) -- [null,null,2,null,3]
~~ json.decode 将 JSON 字符串解码为表格对象。 格式: table = json.decode(string)
用法示例: local json = require("framework.shared.json")
local tb = json.decode('{"a":1,"b":"ss","c":{"c1":1,"c2":2},"d":[10,11],"1":100}')
dump(tb) --[[
- "<var>" = {
- "1" = 100
- "a" = 1
- "b" = "ss"
- "c" = {
- "c1" = 1
- "c2" = 2
- }
- "d" = {
- 1 = 10
- 2 = 11
- }
- }
]]
local tb = json.decode('[1,2,"3",[10,11]]')
dump(tb) --[[
- "<var>" = {
- 1 = 1
- 2 = 2
- 3 = "3"
- 4 = {
- 1 = 10
- 2 = 11
- }
- }
]]

lua -- encode and decode的更多相关文章

  1. [LeetCode] Encode and Decode Strings 加码解码字符串

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...

  2. 【python】python新手必碰到的问题---encode与decode,中文乱码[转]

    转自:http://blog.csdn.net/a921800467b/article/details/8579510 为什么会报错“UnicodeEncodeError:'ascii' codec ...

  3. LeetCode Encode and Decode Strings

    原题链接在这里:https://leetcode.com/problems/encode-and-decode-strings/ 题目: Design an algorithm to encode a ...

  4. Encode and Decode Strings

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...

  5. encode和decode

    Python字符串的encode与decode研究心得乱码问题解决方法 为什么会报错“UnicodeEncodeError: 'ascii' codec can't encode characters ...

  6. 【python】浅谈encode和decode

    对于encode和decode,笔者也是根据自己的理解,有不对的地方还请多多指点. 编码的理解: 1.编码:utf-8,utf-16,gbk,gb2312,gb18030等,编码为了便于理解,可以把它 ...

  7. 271. Encode and Decode Strings

    题目: Design an algorithm to encode a list of strings to a string. The encoded string is then sent ove ...

  8. [LeetCode#271] Encode and Decode Strings

    Problem: Design an algorithm to encode a list of strings to a string. The encoded string is then sen ...

  9. Encode and Decode Strings 解答

    Question Design an algorithm to encode a list of strings to a string. The encoded string is then sen ...

随机推荐

  1. WinHttp编写HTTP服务器示例代码

    这是微软提供的示例程序,原文地址在此https://msdn.microsoft.com/en-us/library/windows/desktop/aa364640(v=vs.85).aspx HT ...

  2. Docker安装和常用命令

    Docker安装 Docker的安装可以参考 https://docs.docker.com/ 下面的 Get Docker / Docker CE / Linux, 需要关注的主要是CentOS和U ...

  3. 基于RecyclerView实现的分组显示信息demo

    发布时间:2018-11-07   技术:Android Studio 3.1.3+ RecyclerView+sectionRecyclerViewAdapter   概述 利用sectionedR ...

  4. Linux系统Ubuntu安装zookeeper

    1. 下载zookeeper二进制安装包 下载地址:http://apache.dataguru.cn/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz ...

  5. Cmake编译SDL2

    cmake -G"NMake Makefiles" && nmake 中出现了以下这个RC资源编译器报告的错误: invalid language id when ...

  6. Git提交代码报错Git push error:src refspec XXX matches more than one解决方案

    Git提交代码push时,报错这个 error: src refspec master matches more than one. error: failed to push some refs t ...

  7. 超高频RFID模块

    1.应用开发有两种方法:串口和USB 2.从逻辑上将标签存储器分为四个存储区,每个存储区可以由一个或一个以上的存储器字组成.这四个存储区是: 00 保留区(Password):前两个字是销毁(kill ...

  8. SpringBoot中Redis的set、map、list、value、实体类等基本操作介绍

    今天给大家介绍一下SpringBoot中Redis的set.map.list.value等基本操作的具体使用方法 上一节中给大家介绍了如何在SpringBoot中搭建Redis缓存数据库,这一节就针对 ...

  9. linux 文件系统工作原理

    转:<http://linuxperf.com/?p=153> 一.概述 文件系统要解决的一个关键问题是怎样防止掉电或系统崩溃造成数据损坏,在此类意外事件中,导致文件系统损坏的根本原因在于 ...

  10. System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded

    昨天客户跟我说,突然一个页面频繁地报ThrowIfMaxHttpCollectionKeysExceeded这个异常.而且是数据量大的时候报错,数据量小的时候OK. 根据异常的名称也能看得差不多超过了 ...