Hi,
When attempting to read a JSON formatted data in Hype, JSON Parse function raises an error as: Unexpected identifier “object”, even when the provided data is valid in other javascript frameworks, like Appcelerator.
in HTML header, I am including the corresponding line to load the data like .js file as follow:
<script type="text/javascript" src="${resourcesFolderName}/data.js"></script>
then I have a setup function to read and decode the data.js by doing:
//Get data from JSON file
window.myData = JSON.parse(data);
with this format (data.js) it produces the above error:
var data = [
{"id":"1",
"question":"something",
"answer":"D",
"A":"Xmod_write",
"B":"All",
"C":"None",
"D":"both a) and b)",
"E":"a), b) and c)",
"status":""}
];
If I change the file (data.js) as follow by adding ’ symbol:
var data = '[
{"id":"1",
"question":"something",
"answer":"D",
"A":"Xmod_write",
"B":"All",
"C":"None",
"D":"both a) and b)",
"E":"a), b) and c)",
"status":""}
]';
it produces the following error at parse:
SyntaxError: Unexpected EOF
Error in setup: ReferenceError: Can't find variable: data
and if I try pure JSON format as follow:
"data" : [
{"id":"1",
"question":"something",
"answer":"D",
"A":"Xmod_write",
"B":"All",
"C":"None",
"D":"both a) and b)",
"E":"a), b) and c)",
"status":""}
]
and this is the error produced:
SyntaxError: Unexpected token ':'. Parse error.
(anonymous function) data.js:1 HYPE-466.thin.min.js:14:99
Error in setup: ReferenceError: Can't find variable: data
However the only format that worked for me so far was:
data = '[{"id": "1", "question":"something", "answer": "D", "A": "Xmod_write", "B": "All", "C": "None", "D": "both a) and b)", "E": "a), b) and c)", "status": "noAnswered"},{"id": "2", "question":"something", "answer": "D", "A": "Xmod_write", "B": "All", "C": "None", "D": "both a) and b)", "E": "a), b) and c)", "status": "noAnswered"}]';
So, question is why only this format is accepted in Hype when the other format still valid for pure javascript code?
Regards,
Flavio