I am struggling to display the contents of my JSON file in Nativescript using console commands. My goal is to showcase these contents and leverage the values in the file to perform additional functions.
Here is the Javascript function that I have tweaked slightly from NS documentation and Emil Oberg's solution on a different thread:
var fs = require('file-system');
var documents = fs.knownFolders.documents();
var jsonFile = documents.getFile('/Users/student/Desktop/Native_Script/Library/app/images/status.json');
var array;
var jsonData;
jsonFile.readText()
.then(function (content) {
try {
jsonData = JSON.parse(content);
array = new observableArrayModule.ObservableArray(jsonData);
} catch (err) {
console.log(err);
}
console.log('Item:' + JSON.stringify(jsonData));
});
////////////////
JSON File:
[{
"Status": "3",
"Trend": "increase",
"Space": "Gleason"
}, {
"Status": "2",
"Trend": "decrease",
"Space": "PRR"
}, {
"Status": "4",
"Trend": "stable",
"Space": "WBR"
}, {
"Status": "1",
"Trend": "decrease",
"Space": "HCR"
}]
If anyone can point out where I might be making a mistake and advise me on how to display any component of the file in the console, I would greatly appreciate it. The main objective is to utilize one of the values in the file, such as status, to invoke another function.
For instance, something along the lines of: (pseudocode)
status.getvalue .then(function) if status > 3 console.log(place is crowded)