Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

processing.data.JSONObject to org.json.JSONObject conversion

$
0
0

I am using PubNub to publish data coming from my processing script. The trouble I am having is that the publish command expects a org.json.JSONObject and I cannot for the life of me get processing to make a org.json.JSONOnject. I have the libraries installed in the sketch and the processing IDE recognizes the class, but I get the error: "Unhandled exception type JSONException". At this point I am just using a very simple example JSON builder code for org.json taken from this site: http://theoryapp.com/parse-json-in-java/ but I have tried many different combinations. Here is my current code:

 import org.json.*;

  void setup() {
     String str = "{ \"name\": \"Alice\", \"age\": 20 }";
     org.json.JSONObject obj = new org.json.JSONObject(str);
     String n = obj.getString("name");
     int a = obj.getInt("age");
     println(n + " " + a);
   }

  void draw() {
   }

I am wondering if anybody has used org.json.JSONObject successfully or if there is someway to make a processing JSON object recognizable by others as a viable org.json.JSONObject.


Viewing all articles
Browse latest Browse all 2896

Trending Articles