Corona query builder runtime error

0 votes
local App42API = require("App42-Lua-API.App42API")
local queryBuilder = require("App42-Lua-API.QueryBuilder")
local JSON = require("App42-Lua-API.JSON")
--local userService = App42API:buildUserService()

local userName = "Serafettin"
local key1 = "name"
local value1 = "hg"
local query = queryBuilder:build(key1, value1, Operator.EQUALS)
App42API:setDbName("TESTDB1");
App42API:initialize(Constant.apiKey,Constant.secretKey)
local userService = App42API:buildUserService()
userService:setQuery("users",query);
local App42CallBack = {}
userService:getUser(userName,App42CallBack)
function App42CallBack:onSuccess(object)
print("userName is "..object:getUserName())
print("emailId is "..object:getEmail())
print("getDocId is "..object:getJsonDocList():getDocId())
print("getCreatedAt is "..object:getJsonDocList():getCreatedAt());
print("getUpdatedAt is "..object:getJsonDocList():getUpdatedAt());
print("Doclist Name is "..JSON:encode(object:getJsonDocList():getJsonDoc()));
end
function App42CallBack:onException(exception)
print("Message is : "..exception:getMessage())
print("App Error code is : "..exception:getAppErrorCode())
print("Http Error code is "..exception:getHttpErrorCode())
print("Detail is : "..exception:getDetails())
end
 
 
 
16:02:53.832  ERROR: Runtime error
16:02:53.832  C:\Users\ttt\Documents\Corona Projects\testapp42\scene1.lua:180: attempt to call method 'getDocId' (a nil value)
16:02:53.832  stack traceback:
16:02:53.832   [C]: in function 'getDocId'
16:02:53.832   C:\Users\ttt\Documents\Corona Projects\testapp42\scene1.lua:180: in function 'onSuccess'
16:02:53.832   C:\Users\ttt\Documents\Corona Projects\testapp42\App42-Lua-API\RestConnector.lua:154: in function <C:\Users\ttt\Documents\Corona Projects\testapp42\App42-Lua-API\RestConnector.lua:142>
 
I am unable to identify what causes this. Thanks for your help in advance.
asked Jun 11, 2017 in Corona by hayrettin.gokturk (10 points)

1 Answer

0 votes

Got it working as:

 

local y = JSON:decode(object:getStrResponse())
print(y.app42.response.users.user.jsonDoc[1])

All user additional data is under y.app42.response.users.user.jsonDoc[1]

For example: y.app42.response.users.user.jsonDoc[1].level

answered Jun 11, 2017 by hayrettin.gokturk (10 points)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...