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
008c17ef
Commit
008c17ef
authored
Jan 08, 2016
by
Marcel Stör
Browse files
Update for consistency with the other docs
parent
affa61ec
Changes
1
Hide whitespace changes
Inline
Side-by-side
docs/en/modules/cjson.md
View file @
008c17ef
#
cjson
Module
#
CJSON
Module
The JSON support module. Allows encoding and decoding to/from JSON.
The JSON support module. Allows encoding and decoding to/from JSON.
...
@@ -12,12 +12,12 @@ Encode a Lua table to a JSON string.
...
@@ -12,12 +12,12 @@ Encode a Lua table to a JSON string.
`cjson.encode(table)`
`cjson.encode(table)`
####Parameters
####Parameters
-
`table`
:
data to encode
`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.
While it also is possible to encode plain strings and numbers rather than a table, it is not particularly useful to do so.
####Returns
####Returns
string
:in json format
JSON
string
####Example
####Example
```
lua
```
lua
...
@@ -28,7 +28,7 @@ else
...
@@ -28,7 +28,7 @@ else
print
(
"failed to encode!"
)
print
(
"failed to encode!"
)
end
end
```
```
__
_
## cjson.decode()
## cjson.decode()
Decode a JSON string to a Lua table.
Decode a JSON string to a Lua table.
...
@@ -37,14 +37,13 @@ Decode a JSON string to a Lua table.
...
@@ -37,14 +37,13 @@ Decode a JSON string to a Lua table.
`cjson.decode(str)`
`cjson.decode(str)`
####Parameters
####Parameters
-
`str`
: The
JSON string to decode
`str`
JSON string to decode
####Returns
####Returns
table
:Lua
representation of the JSON data
Lua
table representation of the JSON data
####Example
####Example
```
lua
```
lua
t
=
cjson
.
decode
(
'{"key":"value"}'
)
t
=
cjson
.
decode
(
'{"key":"value"}'
)
for
k
,
v
in
pairs
(
t
)
do
print
(
k
,
v
)
end
for
k
,
v
in
pairs
(
t
)
do
print
(
k
,
v
)
end
```
```
__
_
\ No newline at end of file
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