UPDATE: I figured it out but will leave this here for others. The solution was to index the table with a string index not a numeric one.
=============================================
I retrieve a json table online such as:
[
{
“item1”: “Some entry here”,
“item2”: “Some entry here”,
“item3”: “Some entry here”,
“item4”: “Some entry here”,
“item5”: “Some entry here”
},
{
“item1”: “Some entry here”,
“item2”: “Some entry here”,
“item3”: “Some entry here”,
“item4”: “Some entry here”,
“item5”: “Some entry here”
},
]
After using the Corona json.decode I can access item 3 in the 2nd table array like this:
local whatever = decodedArray[2][“item3”];
and #decodedArray returns the number of items in the table. HOWEVER,
I access another table which is like this:
{
“numFound”: 789,
“0”: {
“item1”: “Some entry here”,
“item2”: “Some entry here”,
“item3”: “Some entry here”,
“item4”: “Some entry here”,
“item5”: “Some entry here”
},
“1”: {
“item1”: “Some entry here”,
“item2”: “Some entry here”,
“item3”: “Some entry here”,
“item4”: “Some entry here”,
“item5”: “Some entry here”
},
}
#decodedArray returns 0 and I can’t access the individual arrays. I can see them in the debugger. decodedArray.numFound returns 789.
The main difference I see is the first decoded table starts and ends with “[]” and the second starts and ends with “{}” and the 2nd one I’m having problems with has a label before each table entry.
Any thoughts on accessing a table that starts end ends with braces?