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

How do I use JSONDecode to get an item from a table in an JSONEncoded string?

Asked by 4 years ago

Code is below v

local a = {
    b = {
        'hi'
        }
    }


local c = game:GetService("HttpService"):JSONEncode(a)

local decoded = game:GetService("HttpService"):JSONDecode(c)

print(decoded.b.hi)

1 answer

Log in to vote
0
Answered by
gullet 471 Moderation Voter
4 years ago

You're doing everything correctly except that your table a, has an index b with the value of a table with the index of 1, with the value of hi. You're indexing your b table with hi (this is the value, not they key) you need to index it by 1 to get the value "hi" back.

print(decoded.b[1])
Ad

Answer this question