Variable and Function Questions

hklotz13
Sun, 25 Apr 2021 17:31:59 +0000
Coding Questions

please format code with </> button * homework policy * asking questions

Hi there folks. I’m very much a beginner, and I’m currently very lost trying to troubleshoot a project I’m working on for a class. Essentially I’m just trying to make a bar graph with JSON from my Spotify account. I keep getting two errors: “the variable ‘i’ does not exist” and “the method getJSONObject(String) in the type JSONObject is not applicable for the arguments (int)”. I’ve been following a tutorial from my professor in which writes similar code, but for some reason it isn’t working for me. Here’s my code:
</>import processing.data.JSONObject;
void setup(){
size(800,800);
}
void draw() {
JSONObject spotify = loadJSONObject(“StreamingHistory0.json”);
JSONArray tracks = spotify.getJSONArray(“msPlayed”);
for(int i = 0; i < spotify.size(); i++){
JSONObject thisTrack = spotify.getJSONObject(i);
println(thisTrack.getFloat(“msPlayed”));
}
rect(50*i,height,-40,-100);
}</>

Can anyone help me figure out where I went wrong? Thank you!

7 posts - 4 participants