Created
March 17, 2015 02:04
-
-
Save hosaka/64cb5469c7323fc92ccc to your computer and use it in GitHub Desktop.
very crude but minimal JSON encode/decode in LUA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- json parsing | |
function json_decode(msg) | |
local js = {} | |
for k,v in string.gmatch(msg,'"(%w+)":"(%w+)",') do | |
js[k] = v; | |
end | |
for k,v in string.gmatch(msg,'"(%w+)":"(%w+)"}') do | |
js[k] = v; | |
end | |
return js | |
end | |
function json_encode(map) | |
local msg = "{" | |
for k,v in pairs(map) do | |
msg = msg..'"'..k..'":"'..v..'",' | |
end | |
return string.sub(msg,0,-2)..'}' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment