Hey! I’ve been trying to get the servers of a game and it just doesnt work, It says “Can’t parse JSON”
Code:
local HttpService = game:GetService("HttpService")
function getServerList(placeId)
local cursor
local servers = {}
repeat
local response = HttpService:JSONDecode(HttpService:GetAsync("https://games.rprxy.xyz/v1/games/" .. placeId .. "/servers/Public?sortOrder=Asc&limit=100" .. (cursor and "&cursor=" .. cursor or "")))
for _, v in pairs(response.data) do
table.insert(servers, v)
end
cursor = response.nextPageCursor
until not cursor
return servers
end
local srv = getServerList(game.PlaceId)
print(srv)
Before trying to decode the json, you should verify that what what the proxy is returning is json. In cases where the request fails (either GetAsync(), but that would throw an error, or the proxy itself) something other than json can be returned
For example, this is a custom proxy of mine, and it has a Result.Success field, for if the proxy was successful, and a Result.Body field, which is either an error message, or the json
local function GetExperiencesInfo(Body) : RequestTypes?
local Success, Result = pTimeout(60,function()
return HttpService:RequestAsync({
Url = Url.."/api",
Method = "POST",
Headers = {
["Authorization"] = SecurityKey,
["Content-Type"] = "application/json",
},
Body = Body,
})
end)
if Success and Result.Success then
return HttpService:JSONDecode(Result.Body)
else
if not Success then
if Result == "HttpError: ConnectFail" or Result == "HttpError: Timedout" then return false end -- Ignore
warn("[Proxy][Error]: "..Result)
return nil
else
warn("[Proxy][Error]: "..Result.Body)
return nil
end
end
end
pTimeout is like a pcall but with a timeout parameter
Also note that this is a POST request, and not a GET request like GetAsync. But just print what you are getting from GetAsync directly, and then you’ll see what kind of data you are dealing with