We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I have been trying to get acquainted with prof Schiffman's JSON parsing tutorial. I am trying to add names to bubbles. It should be easy, but I'm missing something here. Any help would be greatly appreciated.
var x = 0;
var spaceData;
function setup() {
createCanvas(400, 400);
loadJSON("http://" + "api.open-notify.org/astros.json", gotData, "jsonp");
//json object
}
function gotData(data) {
spaceData = data
}
function draw() {
background(0);
if (spaceData) {
randomSeed(4);
for (var i = 0; i < spaceData.number; i++) {
var rx = random(height);
var ry = random(width);
fill(255);
ellipse(rx, ry, 16, 16);
textSize(15);
text(spaceData.people, rx, ry);
}
}
}
Answers
Is the JSON parsing tutorial that you are working from available online?
yes.
A very small modification made it worked. Something odd that is happening to me right now is that I don't seem to have access to the server holding the data. Maybe things will come to normal shortly.
Kf
Some online loadJSON() example: https://ThimbleProjects.org/gotoloop/91698/
Original forum thread: https://forum.Processing.org/two/discussion/17813/how-to-pull-and-show-text-from-a-json-file#Item_6
I didn't walk through this tutorial.
However, when I downloaded the example code from GitHub, then renamed the sketch to match folder name, then ran it in the Processing 3.2.1 IDE, the result was: it did not appear to run.
Replacing the index.html with a default index.html file text from a new p5.js sketch did make a flower name text appear in a black window.
All of those JS from libraries/ subfolder are pretty old!
Maybe that's the reason its "index.html" had failed?
@GoToLoop this is very true.