I’m pulling JSON data using the network.request from my server. The JSON is being returned and I’ve validated it at least 100 times to make sure that the returned JSON is valid. In my code I’m doing this.
local json = require("json") local function fetchScoreListener(event) if(event.isError) then print( "Network error!") else local jsonData = event.response local jsonDecoded = json.decode(jsonData) print(jsonDecoded) -- \< -- THIS ALWAYS RETURNS NIL --Make sure JSON is not nil if(jsonDecoded ~= nil) then print("User Rank: " .. jsonDecoded["rank"]) print("Points to Next Rank: " .. jsonDecoded["points\_not\_next\_rank"]) --Loop though users highscores for key2 in pairs(jsonDecoded["users"]) do print(jsonDecoded["users"][key2]["username"]) print(jsonDecoded["users"][key2]["score"]) end end end end
From the code above the event.response is pulling back the json data just fine. However when I print the jsonDecoded variable it is always nil. I can’t seem to figure this out
This is how my JSON is setup
{ "users": [{ "username": "TEST USER1", "score": "135973816" }, { "username": "TEST USER12", "score": "4143165" }], "rank": "16144", "points\_not\_next\_rank": "2493" }
Should I file a bug report or am I missing something in my code?