002json.lua 684 B

12345678910111213141516171819202122232425262728293031323334
  1. local t = {
  2. a = 1,
  3. b = "abc",
  4. c = {
  5. 1,2,3,4
  6. },
  7. d = {
  8. x = false,
  9. j = 111111
  10. },
  11. aaaa = 6666
  12. }
  13. local s = json.encode(t)
  14. log.info("json",s)
  15. local st = json.decode(s)
  16. for i,j in pairs(t) do
  17. if type(j) == "number" or type(j) == "string" or type(j) == "boolean" then
  18. assert(j==st[i],i,"json decode error")
  19. log.info("check",i,st[i])
  20. else
  21. for ii,jj in pairs(j) do
  22. if type(jj) == "number" or type(jj) == "string" or type(jj) == "boolean" then
  23. assert(jj==st[i][ii],i,"json decode error")
  24. log.info("check",i,ii,st[i][ii])
  25. end
  26. end
  27. end
  28. end