JSON data into Coll
hi, I have not used javascript before, but have data that I want to use in JSON files.
I can parse the files this way:
function read(p) {
memstr = "";
data = "";
maxchars = 800;
path = p;
var f = new File(path, "read");
f.open();
if (f.isopen) {
while(f.position<f.eof) {
memstr+=f.readstring(maxchars);
}
f.close();
} else {
post("error\n");
}
UI = JSON.parse(memstr);
}
function dump(){
for(i in UI){
for(j in UI[i]){
return("\n",i,j,UI[i][j]);
}
}
}
However, I cannot sort out how to get this data into a coll object. Any tips?
Peter
check out the Dict JavaScript object docs. You can use setparse to read a JSON string and then push_to_coll. Or possibly just read the JSON file directly into the Dict.
OK I'll have a look - thanks!
Sorry - I really am a novice - where will I find those? I looked here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript
but can't find Dict.
P
https://docs.cycling74.com/max8/vignettes/javascriptinmax
Great! thank you.
hey Tyler, done it! thanks so much - your hints made it possible.
P