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 7 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:

01local HS = game:GetService("HttpService")
02 
03script.Parent.Enter.MouseButton1Click:connect(function()
04    local x = HS:GetAsync("https://getbible.net/json?p=James", false)
05    local y = HS:JSONDecode(x)
06    wait()
07    for i,v in pairs(y)do
08        print(v)
09    end
10end)

1 answer

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

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

also, connect is deprecated, use Connect :D

01local HS = game:GetService("HttpService")
02local x = HS:GetAsync("https://getbible.net/json?p=James", false)
03 
04--Properly format le string
05local y = HS:JSONDecode(x:sub(2):reverse():sub(3):reverse())
06 
07function readTab(tab)
08    local function f(t)
09        wait();
10        for i,v in next,t do --Iterate through each index
11            if type(v) ~= "table" then --if it's not a table
12                if i:match("verse") then --and it's key says 'verse'
13                    print(i.." : "..v); --print it
14                end
15            else --otherwise
View all 25 lines...
0
Thank you so much! MRbraveDragon 374 — 7y
0
But how would I be able to get the verse part? MRbraveDragon 374 — 7y
0
I'm guessing the data I need is inside a Table. How would I access the table? MRbraveDragon 374 — 7y
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 — 7y
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 — 7y
0
Thanks again! MRbraveDragon 374 — 7y
Ad

Answer this question