I’m returning the following string from a Web API service and JSON.Decode is failing. Can any tell me why?
{“UserId":5,“UserName”:“strongMan”,“Email”:"user@email.com”,“DistanceFromMe”:0.0,“FriendCount”:1,“AvailableBombs”:12,“UsedBombs”:134,“Rank”:“Beginner”}
I’ve reduced the object to one property, hence scaling the return value back to {“UserName”:“strongMan”} and it still fails.
<lua>
– API RESPONSE HANDLER
local function handleResponse( event )
print (event.response)
if not event.isError then
local userInfo, pos, msg = json.decode( event.response )
if not decoded then
print( "Decode failed at “…tostring(pos)…”: "…tostring(msg) )
return
else
print( userInfo.UserName )
--loadHomePage( )
end
else
native.showAlert( “Login Failed”, “Network Error”, {“OK”} )
end
return
end
</lua>
Printing event.response produces the JSON code pasted above. The result is… Decode failed at 162: nil