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. [javase学习笔记]-8.3 statickeyword使用的注意细节

    这一节我们看静态在使用过程中应注意的几个细节. 上一节我们在学习成员变量与静态变量的差别时,对于两种变量的调用方式不同一时候出现了"无法从静态上下文中訪问非静态变量"的错误.这个问 ...

  2. 最常用的Java库一览(13年的文章)

    来源于:http://www.importnew.com/7530.html 本文由 ImportNew - 邢 敏 翻译自 programcreek.欢迎加入翻译小组.转载请见文末要求. 写在前面: ...

  3. java正则表达式去除html中所有的标签和特殊HTML字符(以&开头的)

    来源于:https://www.androiddev.net/java%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%8E%BB%E9%99%A4ht ...

  4. ios中ASIHTTPRequst的封装

    #import <Foundation/Foundation.h> #import "ASIHTTPRequest.h" #import "ASIDownlo ...

  5. iphone3g 蜂窝数据有效设置

    iphone3g 蜂窝数据有效设置 蜂窝数据     APN cmnet/空     用户名 空     A密码 空彩信(默认为空,需要控制的话,可以设置)     APN cmwap/空     用 ...

  6. java 图片与文字生成PDF

    1.jar包:iText-2.1.5.jar 2.code: import java.awt.Color; import java.io.File; import java.io.FileNotFou ...

  7. Sentinel 简介与API订阅发布

    Sentinel 简介 Redis 的 Sentinel 系统用于管理多个 redis 服务器(instance), 该系统执行以下三个任务: 监控(Monitoring): Sentinel 会不断 ...

  8. 微信支付中的jsapi返回提示信息

    jsapi中跳转到微信支付中触发的方法是js中的getBrandWCPayRequest方法. 改方法中的返回结果msg提示信息如下: err_msg:get_brand_wcpay_request: ...

  9. OpenCV 学习笔记 02 处理文件、摄像头和图形用户界面

    在处理文件前需要引入OpenCV库,同时也引入unmpy库 import cv2 import numpy as np 1 基本的读写操作 1.1 图像文件的读写操作 1.1.1 图像文件的读取操作 ...

  10. Activity 变成对话框,然后再隐藏?

    由于继续需要做一些无感操控的工作,之前也记录了下利用悬浮窗的方法.今天突然发现原来activity可以直接嗯嗯嗯啊. 首先我在AndroidManifest里给activity添加了如下一行: and ...