Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

6 comments

0

Thank you so much!

0

But how would I be able to get the verse part?

0

I'm guessing the data I need is inside a Table. How would I access the table?

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

0

If this is too disorganized still, note you can manually make a bunch of generic for loops to isolate each individual potential value.

0

Thanks again!

This discussion is preserved as it was. New answers, comments, and votes are closed.