Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON string not parsing properly #55

Open
afuhrtrumpet opened this issue Feb 16, 2014 · 0 comments
Open

JSON string not parsing properly #55

afuhrtrumpet opened this issue Feb 16, 2014 · 0 comments

Comments

@afuhrtrumpet
Copy link

Hi, I have been trying to parse this string using aJson

{ "songs": [ { "name": "Song Of Time", "notes": [69, 62, 65, 69, 62, 65, 69, 72, 71, 67, 65, 67, 69, 62, 60, 64, 62], "times": [600, 900, 600, 600, 900, 600, 300, 300, 600, 600, 300, 300, 600, 600, 300, 300, 900], "nunchuck": [3, 1, 2, 3, 1, 2] } ] }

using this code

aJsonObject* root = aJson.parse(songText);
  aJsonObject* songData = aJson.getObjectItem(root, "songs");
  aJsonObject* song = aJson.getArrayItem(songData, 0);
  aJsonObject* songName = aJson.getObjectItem(song, "name");
  songs[0].name = songName->valuestring;
  aJsonObject* noteData = aJson.getObjectItem(song, "notes");
  aJsonObject* timeData = aJson.getObjectItem(song, "times"); 
  int numberNotes = aJson.getArraySize(noteData);
  for (int i = 0; i < numberNotes; i++) {
    aJsonObject* note = aJson.getArrayItem(noteData, i);
    aJsonObject* time = aJson.getArrayItem(timeData, i);
    songs[0].notes.push_back(note->valueint);
    songs[0].notes.push_back(time->valueint);
  }
  aJsonObject* nunchuckData = aJson.getObjectItem(song, "nunchuck");
  int numberNunchuck = aJson.getArraySize(nunchuckData);
  for (int i = 0; i < numberNunchuck; i++) {
    aJsonObject* note = aJson.getArrayItem(nunchuckData, i);
    songs[0].nunchuck_notes.push_back(note->valueint);
  }

And have been getting an empty string for the name, and usually identical random numbers for the other two. I am not sure what the issue is here, but I don't think it is memory as I had 651 bytes of memory remaining when I checked. Could it be the extra whitespace in the string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant