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. android事务队列处理的实现

    代码地址如下:http://www.demodashi.com/demo/14748.html 前言 在android开发中,我们经常会遇到一种情况,随时接收并处理服务端发过来的消息,当服务端发过来的 ...

  2. oracle 、mysql、 sql server使用记录

    oracle .mysql. sql server使用记录 mysql常用命令: mysqld --启动mysql数据库 show databases; -- 查看数据库 use database; ...

  3. [转载]Error starting Sun's native2ascii:

    原文地址:Error starting Sun's native2ascii:作者:大一吧浪 Error starting Sun's native2ascii: at org.apache.tool ...

  4. @Transactional注解事务不回滚不起作用无效

     写在前面 数据库Mysql8.0 添加@Transactional注解后事务并未起作用. 修改表的引擎后ok了.(详看下面转载内容) ================================ ...

  5. Android轻量级ORM框架ActiveAndroid入门教程(转)

    注:没有找到出处,如有侵犯,请告知 开始ActiveAndroid神奇之旅: 在AndroidManifest.xml中我们需要添加这两个 AA_DB_NAME (数据库名称,这个name不能改,但是 ...

  6. sikuli 如何 清空文本框中的内容??解决方法!

    Screen s = new Screen(); s.click("name.png"); s.type("a",KeyModifier.CTRL); s.ty ...

  7. 重写Checkbox 改写选择框的大小

    /* 作者:Starts_2000 * 日期:2009-07-30 * 网站:http://www.csharpwin.com CS 程序员之窗. * 你可以免费使用或修改以下代码,但请保留版权信息. ...

  8. memcached缓存基本概念

    Memcached是一套分布式内存对象缓存系统. 用于在动态应用系统中缓存数据库的数据,减少数据库的访问压力,达到提升网站系统性能的目的:memcached在企业应用场景中一般是用来作为数据库的cac ...

  9. 使用java修改图片DPI

    修改以后可以直接用PS打开看效果 全部使用rt下的类,无需下载其他jar包 import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.imag ...

  10. 【java】详解JFrame结构的分层

    在这篇博文中,笔者会介绍JFrame窗口的分层.JFrame继承自Frame,同JFrame.JDialog.JApplet都是重量级组件.如果不弄清楚Frame的分层结构,那么在设置组件的某些特效的 ...