Loading...
Logo
Processing Forum
when I try and use loadJSONObject(filename)

I have json = loadJSONObject("ufo_awesome.json");

Exactly like in the reference, but every time it gives me an error "loadJSONObject(String) does not exist"  

anybody know about this?? 

please help 
thanks 


Replies(6)


did you creat the file ufo_awesome.json at all?

does the content look ok in notepad?

do you have the spelling of ufo_awesome.json exactly the same in the code and your file name on the hard drive?


It must be in the project's "data" folder.

see
http://www.processing.org/reference/loadJSONObject_.html
etc.


Greetings, Chrisir

If you need an answer, please send me a personal message since this forum doesn't notify.
What version of Processing do you use?

yeah, you should update to the newest version


Ya I'm not using the latest version, but it is 2+ 
ya the file name is spelled correctly, :)
json's in the data folder and contents good... 
 I'll try and update and see if it changes anything. 

Thanks!


- So I updated to the newest version and it works! 


-Thanks!
 

in line
json = loadJSONObject("ufo_awesome.json");
maybe the
name json irritates him, try jsontest
jsontest = loadJSONObject("ufo_awesome.json");

also you must use
jsontest = loadJSONObject("ufo_awesome.json");
after the command size

also maybe the name of your sketch is irritating him (when the name is the same as a class e.g. or is json?)




this works for me


Copy code
  1. // The following short JSON file called "data.json" is parsed
  2. // in the code below. It must be in the project's "data" folder.
  3. //
  4. // {
  5. //   "id": 0,
  6. //   "species": "Panthera leo",
  7. //   "name": "Lion"
  8. // }
  9. JSONObject json;
  10. String stateString="Press 1 or 2";
  11. void setup() {
  12.   size (800, 800);
  13.   background(0);
  14. }
  15. void draw() {
  16.   background(0);
  17.   fill(255);
  18.   text ("1 - save JSON", 111, 111);
  19.   text ("2 - load JSON", 111, 131);
  20.   fill(255, 2, 2);
  21.   text (stateString, 111, 181);
  22. }
  23. void keyPressed() {
  24.   switch(key) {
  25.   case '1':
  26.     saveTest() ;
  27.     break;
  28.   case '2':
  29.     loadTest();
  30.     break;
  31.   default:
  32.     // do nothing
  33.     stateString="Press 1 or 2";
  34.     break;
  35.   } // switch
  36. } // func
  37. //
  38. // ----------------------------------------------------------
  39. void saveTest() {
  40.   json = new JSONObject();
  41.   json.setInt("id", 0);
  42.   json.setString("species", "Panthera leo");
  43.   json.setString("name", "Lion");
  44.   saveJSONObject(json, "data/new.json");
  45.   println ("saved");
  46.   stateString="saved";
  47.   // Sketch saves the following to a file called "new.json":
  48.   // {
  49.   //   "id": 0,
  50.   //   "species": "Panthera leo",
  51.   //   "name": "Lion"
  52.   // }
  53. }
  54. // ----------------------------------------------------------
  55. void loadTest() {
  56.   json = loadJSONObject("new.json");
  57.   int id = json.getInt("id");
  58.   String species = json.getString("species");
  59.   String name = json.getString("name");
  60.   println(id + ", " + species + ", " + name);
  61.   stateString="loaded:    " + id + ", " + species + ", " + name;
  62.   //
  63.   // Sketch prints:
  64.   // 0, Panthera leo, Lion
  65. }
  66. //


Greetings, Chrisir   

If you need an answer, please send me a personal message since this forum doesn't notify.