donzee529
(Donzee)
December 17, 2020, 11:41pm
#1
{
"products": {
"Mercedes Econic Fuel Truck": {
"name": "Mercedes Econic Fuel Truck",
"preorder": false,
"devproduct": 1130599874,
"users": {
"1": {
"status": true,
"id": "1"
}
}
},
"Boeing 737 V1": {
"name": "Boeing 737 V1",
"preorder": true,
"devproduct": 1130600202,
"users": {
"1": {
"status": true,
"id": "1"
},
"362190114": {
"status": true,
"userid": "362190114"
}
}
}
}
}
That has been retrieved using an API. How can I get lets say, the first JSON Entries name value?
SketchySong
(FruityAntlers)
December 17, 2020, 11:49pm
#2
You can use HttpService:JSONDecode()
to decode retrieved JSON data to a table.
donzee529
(Donzee)
December 17, 2020, 11:50pm
#3
How do I get the data though? Just the name value from the first entree.
SketchySong
(FruityAntlers)
December 17, 2020, 11:54pm
#4
Same as how you get data from normal tables, in this case it would be:
local ProductTable = {
--Your JSONDecoded Table
}
function getProducts()
local ReturnTable = {}
for i, v in pairs(ProductTable) do
ReturnTable[#ReturnTable + 1] = i
end
end
donzee529
(Donzee)
December 17, 2020, 11:55pm
#5
And what would that retrieve exactly?
SketchySong
(FruityAntlers)
December 17, 2020, 11:56pm
#6
The name of products, like Boeing 737 V1 and Mercedes Econic Fuel Truck by your table above.
donzee529
(Donzee)
December 17, 2020, 11:57pm
#7
and how would I let say get the dev product of the Boeing product?
You use the id that you fetched
donzee529
(Donzee)
December 17, 2020, 11:58pm
#9
what Id did I fetch? huh???
Donzee_Boi:
{
"products": {
"Mercedes Econic Fuel Truck": {
"name": "Mercedes Econic Fuel Truck",
"preorder": false,
"devproduct": 1130599874,
Right here, you said that this is retrieved from an API
donzee529
(Donzee)
December 18, 2020, 12:00am
#11
And how do I get to the devproduct from here "Mercedes Econic Fuel Truck": {
SketchySong
(FruityAntlers)
December 18, 2020, 12:00am
#12
Simple manipulation will do
local ProductTable = {
--Your JSONDecoded Table
}
function getProducts()
local ReturnTable = {}
for i, v in pairs(ProductTable) do
ReturnTable[i] = {devproduct = ProductTable[i]["devproduct"]}
end
end
2 Likes
donzee529
(Donzee)
December 18, 2020, 12:01am
#13
Thanks so much, I really appreicate it