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

Can't Parse JSON? I need some HttpService help.

Asked by 6 years ago

So i'm trying to get a table off a website... But I can't seem to get it. Any idea why? Heres my scirpt:

local HS = game:GetService("HttpService")

script.Parent.Enter.MouseButton1Click:connect(function()
    local x = HS:GetAsync("https://getbible.net/json?p=James", false)
    local y = HS:JSONDecode(x)
    wait()
    for i,v in pairs(y)do
        print(v)
    end
end)

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years ago
Edited 6 years ago

The site you provided does not have a properly formatted string.

also, connect is deprecated, use Connect :D

local HS = game:GetService("HttpService")
local x = HS:GetAsync("https://getbible.net/json?p=James", false)

--Properly format le string
local y = HS:JSONDecode(x:sub(2):reverse():sub(3):reverse())

function readTab(tab)
    local function f(t)
        wait();
        for i,v in next,t do --Iterate through each index
            if type(v) ~= "table" then --if it's not a table
                if i:match("verse") then --and it's key says 'verse'
                    print(i.." : "..v); --print it
                end
            else --otherwise
                f(v) --do this all again on the table
            end
        end
    end
    f(tab);
end

script.Parent.Enter.MouseButton1Click:Connect(function()
    readTab(y);
end)
0
Thank you so much! MRbraveDragon 374 — 6y
0
But how would I be able to get the verse part? MRbraveDragon 374 — 6y
0
I'm guessing the data I need is inside a Table. How would I access the table? MRbraveDragon 374 — 6y
0
It seems you have multiple tables inside of eachother. I wrote you a little function to pick through them and isolate the verses to print Goulstem 8144 — 6y
View all comments (2 more)
0
If this is too disorganized still, note you can manually make a bunch of generic for loops to isolate each individual potential value. Goulstem 8144 — 6y
0
Thanks again! MRbraveDragon 374 — 6y
Ad

Answer this question