I have a string that has the value of a player's name. It was in a table and I converted it correctly using the JSONEncode() function (which is 100% correct). There are two symbols that are left over from the conversion - these square brackets [ ]. I'm trying to use string.gsub to remove them, but it's not working.
Help would be appreciated asap (:
Here is the code below for what I've tried to do with string.gsub:
local finNames = string.gsub(json,'%[', "") local finXames = string.gsub(finnames,'%]',"") print(finXames)
Use JSONDecode() to convert JSON back into a lua table again. Do not bother trying to parse JSON yourself.
Though you should definitely not do this to parse JSON, here's how you would use gsub:
string.gsub(s, pattern, replace) --for example print(string.gsub("This is a string!", "string!", "gsub'd string!")) --returns and prints "This is a gsub'd string!" print(string.gsub("[This is a string!]", "%[", "")) --returns and prints "This is a string!]"