Advertisement
CloneTrooper1019

Roblox JSON Example :P

Jun 6th, 2014
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. util = LoadLibrary("RbxUtility")
  2. encode = util.EncodeJSON
  3. decode = util.DecodeJSON
  4.  
  5. -- First, I'll create an example table & print its keys/values
  6.  
  7. print(string.rep("-",80))
  8. exampleTable = {
  9.     Description = "This is the description of the item";
  10.     [2] = "This is the 2nd index on my table.";
  11.     ["Text"] = 4;
  12. }
  13.  
  14. print("Example Table Keys and Values:")
  15. print()
  16.  
  17. for key,value in pairs(exampleTable) do
  18.     print(tostring(key).." = "..tostring(value))
  19. end
  20.  
  21. -- Now I'll convert this example into a JSON string and print it.
  22.  
  23. print()
  24. print("JSON Version of the Example table:")
  25. print()
  26. local JSON_String = encode(exampleTable)
  27. print(JSON_String)
  28.  
  29. -- Then reconvert it into a table & print its keys/values
  30.  
  31. print()
  32. print("New Example Keys & Values:")
  33. print()
  34.  
  35. local newExample = decode(JSON_String)
  36. for key,value in pairs(newExample) do
  37.     print(tostring(key).." = "..tostring(value))
  38. end
  39. print(string.rep("-",80))
  40.  
  41. -- You should get the same keys and values as you did when you started.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement