Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why does my script get the error of Can't Parse JSON when using the HTTP service?

Asked by
1lO_Ql1 -1
5 years ago
local HTTP = {}
HTTP.URL = "https://raw.githubusercontent.com/PixelLiten/Nethereal/master/0.0.1/files.json"
local http = game:GetService("HttpService")
function HTTP:HTTPGET(url)
    local success, res = pcall(http.RequestAsync, http, {
        Url = url;
        Method = "GET";
    })
    if (not success) then
        res = {
            Success = false;
            StatusCode = -1;
            StatusMessage = res;
            Headers = nil;
            Body = nil;
        }
    end
    if (not res.Success) then
        warn(url .. " >> " .. res.StatusMessage)
    end
    return res, res.Body
end
function HTTP:HTTPGETJSON(url)
    local success, res = pcall(http.RequestAsync, http, {
        Url = url;
        Method = "GET";
    })
    if (success) then
        local json
        success, json = pcall(http.JSONDecode, http, res.Body)
        if (success) then
            res.Body = json
        else
            res = json
        end
    end
    if (not success) then
        res = {
            Success = false;
            StatusCode = -1;
            StatusMessage = res;
            Headers = nil;
            Body = nil;
        }
    end
    if (not res.Success) then
        warn(url .. " >> " .. res.StatusMessage)
    end
    return res, res.Body
end
function HTTP:Install()
    warn "Fetching file list..."
    local filelistRes, filelist = self:HTTPGETJSON(self.URL)
    if (not filelistRes.Success) then
        warn(filelistRes.StatusMessage)
        return
    end
end
return HTTP

0
Put the full error message, the result of you trying to debug it, which part you think might be the cause, what the script is supposed to do, LITERALLY ANY INFO, don't just make a post and slap a 60 lines of code and hope people will just help you Azure_Kite 885 — 5y

Answer this question