I tried using the API instead of direct mysql connection but I ran into a problem where I couldn't retrieve the API response value. It said it was a string. I tried converting it using toJSON and fromJSON and it didn't work.
function hangetdleApiResponse(data, info)
local json = toJSON(data)
local result = fromJSON(data)
if result then
for _, user in ipairs(result) do // ipairs(json)
iprint("ID: " .. user.id)
iprint("Username: " .. user.username)
iprint("Email: " .. user.email)
end
else
iprint("Error parsing JSON data")
end
end
function getApiData()
local url = 'http://127.0.0.1:8000/user/'
sendOptions = {
connectionAttempts = 3,
connectTimeout = 5000,
method = "GET",
formFields = {},
}
fetchRemote(url, sendOptions, function(data, info)
hangetdleApiResponse(data, info)
end)
end
data repose json
[
{
"id": 49,
"username": "framef318",
"email": "
[email protected]"
},
{
"id": 50,
"username": "framef3188",
"email": "
[email protected]"
}
]