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

Decoding a JSON table using HttpService?

Asked by
nilVector 812 Moderation Voter
9 years ago

I am trying to retrieve the new, "bust" profile picture of a player (the one where it displays your character without any gear item equipped and faces the right side).

According to the wiki article on Web APIs, you have to use that given url to retrieve a JSON table, which you can decode later. That's exactly what I'm trying to do here:

local imageLabel = script.Parent --ImageLabel Object
local myJSON = game:GetService('HttpService'):JSONDecode('http://www.roblox.com/bust-thumbnail/json?userId=17030889&height=180&width=180')
imageLabel.Image = myJSON[1]

myJSON should look something like this: {"Url":"http://t4.rbxcdn.com/6fa936d8b4dc1b86d98f0143bbf20788","Final":true}

However, all I get is an error saying Can't parse JSON.

The wiki article on JSONDecode says that the JSONDecode function does not require HttpEnabled to be true, but I tried it with it both on and off just to be sure, and it still doesn't work.

In addition, I also tried using double-quotes instead of single-quotes for the url, and it still doesn't work.

What am I doing wrong here?

0
1.) You are using JSONDecode on a string. 2.) To obtain the result from the website, HTTPEnabled must be enabled to use 'GetAsync' 3.) You can't access Roblox-links directly from Roblox. DigitalVeer 1473 — 9y
0
Directly from the wiki article on JSONDecode (which I linked in my post, too), it says, "Decodes a JSON string into a Lua table. Does not require HttpEnabled to be true." nilVector 812 — 9y
0
YOU DECODE THE RESULT FROM THE URL. JSONDECODE ONLY WORKS ON A JSON, NOT ON A URL. DigitalVeer 1473 — 9y
0
Nevermind. DataStore actually explained it in more depth in the answer below, so I understand what you mean now. nilVector 812 — 9y
View all comments (6 more)
0
you better DigitalVeer 1473 — 9y
0
I do, because there are people that are better at explaining than you. nilVector 812 — 9y
0
I didn't explain it though. I merely pointed out errors. Perhaps learn the difference between 'listing' and 'explaining.' DigitalVeer 1473 — 9y
0
Maybe learn the difference between a comment and an answer too, k? Don't put up a smartass attitude here if you can't even interpret a simple wiki article. DigitalVeer 1473 — 9y
0
Maybe learn the difference between teaching someone who has a learning gap and straight up insulting them, "k"? I'm sorry for asking a scripting question on a scripting question-asking website. I doubt you understand everything the first time you read something, too, so don't act like you're above everyone else. nilVector 812 — 9y
0
...and just the fact that you down-voted my reputation shows how salty you are. Would you like some pepper with that salt? nilVector 812 — 9y

1 answer

Log in to vote
0
Answered by
DataStore 530 Moderation Voter
9 years ago

There's two issues here, really. (Though, after refreshing both of them have been addressed by 'DigitalVeer' - Nonetheless, I thought I'd post what I had)

1) JSONDecode's argument is meant to contain the JSON you're decoding; what you've provided isn't JSON - Ipso facto, that error occurs.

local HttpService = game:GetService("HttpService")
local Decoded = HttpService:JSONDecode(HttpService:GetAsync("Website")) 

2) You cannot use HttpService with ROBLOX URLs, unless you make use of a some website which makes and returns the request for you.

Two ways to get around the second issue:

1) Mimic what that link does; you can use the ImageRectOffset and ImageRectSize properties of ImageLabels to get the desired effect. 2) Make use of 'rproxy' - Though, with this route you have no idea how long the service will be provided for; it could "go away" anytime.

0
Thanks, but could you elaborate on the 'rproxy' thing? I've never heard of it, and I'm interested in learning about it. nilVector 812 — 9y
0
Nevermind. I just figured out how to use it. I'll accept your answer now. nilVector 812 — 9y
Ad

Answer this question