I cannot load JSONObject with loadJSONObject

edited July 2014 in JavaScript Mode
JSONObject json;
println("hello web!");

   json = loadJSONObject ("URL_HERE");
   println (json); 

Hello all

Above is my code to get the JSONObject from the URL. This code works in Java mode, but in JavaScript mode, it only print 'Hello web!' and stopped.

Where did I wrong?

Thank you very much

Tagged:

Answers

  • edited July 2014

    I also tried the following code:

       println ("Hello 2");
       String str[];
       str = loadStrings ("google.com");
       println ("Hello 3");
       for (int i=0; i < str.length; i++) {
    
           println(str[i]);
    
       }
    
       println ("goodbye");
    

    Basically, it comes from this example:

    http://processingjs.org/reference/loadStrings_/

    But the code only can prints "Hello 2", then stopped.

    Could you give me a hint? Thank you very much.

  • edited July 2014

    I've already given ya a hint: ProcessingJS's site! 8-}
    JS Mode is still far behind Java Mode version 2+! (~~)
    If you look at JS's reference, you won't find any JSON there! [..]

  • edited July 2014

    I don't think "google.com" is a complete URL either! /:)
    Generally, we should only load from "/data/" subfolder in JS Mode! :-S

  • Could you give me a sample URL? I changed loadJSONObject to loadStrings but it still does not work :(

  • Two issues here:

    • As said, ProcessingJS doesn't support Json handling;
    • Even if you used loadStrings(), it won't work in JS, because it doesn't allow to load data from a site different from the one serving the JS.

    And indeed, you would need a full URL with http:// schema.

    So, the only thing you can do is to loadStrings() from your own site.

  • I see

    So is there anyway to load a text from other site in JS, and parse as a JSON?

  • edited July 2014

    I still don't know how all that works. But I guess we gotta request the local server itself to load a remote file
    and place it locally, so it's available for our local app scripts!

  • Or take a look at JsonP.

Sign In or Register to comment.