Convert String To Table

my code:
local url = string.format(“https://pastebin.com/raw%s”, “/” … pastebinId);
local data = httpService:GetAsync(url)
local t = {}
local splitString: table = string.split(data, “”)
print(splitString)
prints out like this:


but, on pastebin i have table like this

what should i do?

Try parsing it into JSON format.

local data = httpService:GetAsync(url)
data = httpService:JSONDecode(data)
2 Likes

i haven’t tested this but try it out

local data = httpService:GetAsync(url) -- raw
data = string.gsub(data, "{", "") -- removes {
data = string.gsub(data, "}", "") -- removes }
data = string.gsub(data, '"', "") -- removes "
data = string.split(data, ", ") -- splits the string

it gives:
Can’t parse JSON

30 letters

Yes, It Works! Thank you, have a nice day.

Right, make sure to encode it first and then decode:

local data = httpService:GetAsync(url)
data = httpService:JSONEncode(data)
data = httpService:JSONDecode(data)

Assuming ofcourse that the source pastebin contains valid JSON.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.