Using JSON from Processing-JS

五迷三道 提交于 2019-12-06 01:21:06

Your Processing code gets "sloppily" parsed and converted into JavaScript. Anything the parser doesn't understand just gets ignored, which means you can freely mix bits of JavaScript code in with your Processing and it will, in general, "just work".

Have a look here for more information: http://processingjs.org/reference/articles/best-pratice

You could use jQuery like this to get JSON results from your server and iterate them to do whatever. I'm sure there wouldn't be a problem with using processing-JS and jQuery together.

i think you should visit www.json.org
There it explains how to use json both server-side and client-side from within a web-app.
Practically there should be many library implementations server-side that you can include in your web applications to transform your platform objects to json objects.
For sure there is an implementation that transforms java objects to JSON objects. To interpret client side data i think you can use another library that it should be on the same web site. The only problem is that i don't know if you can use javascript scripts into processing javascript to use javascript objects

Shoot, I was hoping there would be a better answer here. Here's a tutorial on processing.js's website. All they do is process the JSON using javascript and use it to call functions in your Processing code.

Apparently you don't want to just pass in JSON. You can however, pass in XML, although there isn't XPath support so you've gotta whip out your for loops if you want to get anything out of it.

To pass data from JQuery/ Javascript into Processing.js, you call the global scope function Processing.getInstanceById, which gives you a reference to the Processing PApplet object (well, the javascript equivalent):

// get a reference to the Processing PApplet object:
var proc = Processing.getInstanceById("the_id_of_your_canvas");

Then you can call any functions available in your Processing sketch, e.g.:

// call any function that is defined inside the Processing sketch
// in this case, one of the built in ones:
proc.frameRate(4);

So you write your JSON parsing code in Javascript/ JQuery and can then pass data through to Processing functions like that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!