I wasn’t quite sure where to put this, but i have a question (And a massive brick wall which is holding up my project):
When i run this code:
json = require("json")
keyCode = {}
test = {}
tables = {}
keys = {}
fileContents = {}
i = 1
p = 1
JSONFile = system.pathForFile("QuestionnaireJSON.json")
JSONOpen = io.open(JSONFile, "r")
JSONContents = JSONOpen:read("\*a")
test = json.decode(JSONContents)
answerType = {}
answerType[1] = "edit"
answerType[2] = "memo"
answerType[3] = "check"
answerType[4] = "radio"
answerType[5] = "conbo"
function arrayMapping()
for key, value in pairs(test) do
if type(value) == 'table' then
print(key, value)
tables[i] = value
tables[i].key = key
tables[i].value = value
end
i = i +1
end
end
arrayMapping()
The program runs perfectly fine and i get this output:
records table: 0x186ef1c0
errors table: 0x19d820d0
However when I run this:
json = require("json")
keyCode = {}
test = {}
tables = {}
keys = {}
fileContents = {}
i = 1
p = 1
JSONFile = system.pathForFile("QuestionnaireJSON.json")
JSONOpen = io.open(JSONFile, "r")
JSONContents = JSONOpen:read("\*a")
test = json.decode(JSONContents)
answerType = {}
answerType[1] = "edit"
answerType[2] = "memo"
answerType[3] = "check"
answerType[4] = "radio"
answerType[5] = "conbo"
function arrayMapping()
for key, value in pairs(test) do
print(key, value)
tables[i] = value
tables[i].key = key
tables[i].value = value
i = i +1
end
end
arrayMapping()
I get this error:
records table: 0x18695480
totalRecords 1
Runtime error
/Users/matthewharrop/Documents/Ideagen/main.lua:25: attempt to index field ‘?’ (a number value)
stack traceback:
[C]: ?
/Users/matthewharrop/Documents/Ideagen/main.lua:25: in function ‘arrayMapping’
/Users/matthewharrop/Documents/Ideagen/main.lua:30: in main chunk
Runtime error: /Users/matthewharrop/Documents/Ideagen/main.lua:25: attempt to index field ‘?’ (a number value)
stack traceback:
[C]: ?
/Users/matthewharrop/Documents/Ideagen/main.lua:25: in function ‘arrayMapping’
/Users/matthewharrop/Documents/Ideagen/main.lua:30: in main chunk
Does anybody know why this is happening?
Please help cause i’m so very very stuck
[import]uid: 65237 topic_id: 31132 reply_id: 331132[/import]
[import]uid: 65237 topic_id: 31132 reply_id: 124511[/import]
[import]uid: 65237 topic_id: 31132 reply_id: 124691[/import]