Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
e5de0567
Commit
e5de0567
authored
Jan 06, 2016
by
Johny Mattsson
Browse files
Transferred cjson module documentation.
parent
d3331c20
Changes
2
Hide whitespace changes
Inline
Side-by-side
docs/en/modules/cjson.md
0 → 100644
View file @
e5de0567
# cjson Module
The JSON support module. Allows encoding and decoding to/from JSON.
Please note that nested tables can require a lot of memory to encode. To catch out-of-memory errors, use
`pcall()`
.
## cjson.encode()
Encode a Lua table to a JSON string.
####Syntax
`cjson.encode(table)`
####Parameters
-
`table`
: data to encode
While it also is possible to encode plain strings and numbers rather than a table, it is not particularly useful to do so.
####Returns
string:in json format
####Example
```
lua
ok
,
json
=
pcall
(
cjson
.
encode
,
{
key
=
"value"
})
if
ok
then
print
(
json
)
else
print
(
"failed to encode!"
)
end
```
__
_
## cjson.decode()
Decode a JSON string to a Lua table.
####Syntax
`cjson.decode(str)`
####Parameters
-
`str`
: The JSON string to decode
####Returns
table:Lua representation of the JSON data
####Example
```
lua
t
=
cjson
.
decode
(
'{"key":"value"}'
)
for
k
,
v
in
pairs
(
t
)
do
print
(
k
,
v
)
end
```
__
_
mkdocs.yml
View file @
e5de0567
...
@@ -31,6 +31,7 @@ pages:
...
@@ -31,6 +31,7 @@ pages:
-
Modules
:
-
Modules
:
-
'
adc'
:
'
en/modules/adc.md'
-
'
adc'
:
'
en/modules/adc.md'
-
'
bit'
:
'
en/modules/bit.md'
-
'
bit'
:
'
en/modules/bit.md'
-
'
cjson'
:
'
en/modules/cjson.md'
-
'
crypto'
:
'
en/modules/crypto.md'
-
'
crypto'
:
'
en/modules/crypto.md'
-
'
gpio'
:
'
en/modules/gpio.md'
-
'
gpio'
:
'
en/modules/gpio.md'
-
'
node'
:
'
en/modules/node.md'
-
'
node'
:
'
en/modules/node.md'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment