Addressing Table in Table

I am using a network request to read in data in json format, running a decode to create a table.

It seems as though this is working as I am getting the correct tables being created, but when I try to address an element in the table I am getting no joy.

Attached are several images. The VARIABLE window from Lua Glider that shows the that the table schedFlts has 2 elements, each tables and shows the sub-table 1.

Further screenshots show debug results of the variables.

I am trying to read one of the elements in the sub-table - in this case departureAirportFsCode, but it is not working. 

“Screenshot schedule Flights Table 1 nil.jpg” shows that the value of table 1 (schedFlts[1]) is nil, but when you look at the variable window it is clear that schedFlts[1] is not nil.

Am I trying to address the field in sub-table correctly?

If you have any suggestions, it would be appreciated.

thanks in anticipation

joncb

What would be really helpful is a copy/paste from the console log. I know you’re using Lua Glider and output from the simulator is routed to one of their windows, but you may find this easier to do if you run the simulator directly instead of building out of Glider.

Make sure at the top of that module to require the JSON library:

local json = require("json")

if you have not done so already. Next inside your network request, where you’re printing out the value of network.request, you’re getting a table and the best way to look at this is to do:

print( json.prettify( event.response ) )

Then if you run this using the Corona simulator, you will get a nice big console window that you can use your mouse to select the text and then use copy and paste to paste the results here to see.  Screen shots are hard to work with.

Rob

G’day Rob,

thanks for your response. I ran your suggested print code and it showed that the table was being created correctly, and that the code I was using was correct and that I could access the tables as I needed to.

What got me stumped was that the Lua Glider debugger showed the sub-table schedFLts[1] was nil. I stopped the code at that point, trying to solve the problem - however had I let the code run, it would have provided the information I needed.

When I ran the code in the Corona Simulator it ran fine. I guess this may be more to do with Lua Glider.

Summary - all was good - I was on the right track - but got thrown off by over analysing.

thanks again. You print code will be very useful as a progress in this app.

regards

joncb

Glad you solved it.

Rob

What would be really helpful is a copy/paste from the console log. I know you’re using Lua Glider and output from the simulator is routed to one of their windows, but you may find this easier to do if you run the simulator directly instead of building out of Glider.

Make sure at the top of that module to require the JSON library:

local json = require("json")

if you have not done so already. Next inside your network request, where you’re printing out the value of network.request, you’re getting a table and the best way to look at this is to do:

print( json.prettify( event.response ) )

Then if you run this using the Corona simulator, you will get a nice big console window that you can use your mouse to select the text and then use copy and paste to paste the results here to see.  Screen shots are hard to work with.

Rob

G’day Rob,

thanks for your response. I ran your suggested print code and it showed that the table was being created correctly, and that the code I was using was correct and that I could access the tables as I needed to.

What got me stumped was that the Lua Glider debugger showed the sub-table schedFLts[1] was nil. I stopped the code at that point, trying to solve the problem - however had I let the code run, it would have provided the information I needed.

When I ran the code in the Corona Simulator it ran fine. I guess this may be more to do with Lua Glider.

Summary - all was good - I was on the right track - but got thrown off by over analysing.

thanks again. You print code will be very useful as a progress in this app.

regards

joncb

Glad you solved it.

Rob