cytoscape js, json data format

1,719 views
Skip to first unread message

sl yls

unread,
Nov 12, 2013, 12:14:16 PM11/12/13
to cytoscap...@googlegroups.com
Hi,
Json in cytoscape js is not a real json? I can not process this data correctly. Especially, when I use json.parse, json.encode or jquery.getJSON()
json='[{ data: {id:"oxid"},group:"nodes"}]
it should be like this, otherwise, jQuery.parseJSON(), parseJSON() or jquery.getJSON() can not parse it correctly.
json='[{ "data": {id:"oxid"},"group":"nodes"}]

I want to get the json data automatically by using jquery.getJSON() based on different data I got from users, but it failed. Anyone who has any idea? 
PS. I can create json automatically by printing out the data as I want in the <script> area, but I don't like this method, because I can not reload my data 
automatically by using cy.load(). I hope there is one way that I can just pass an argument to cy.load() to reload my graph. something like this cy.load(json_data), here
json_data is a string variable.

Max Franz

unread,
Nov 14, 2013, 12:08:29 PM11/14/13
to cytoscap...@googlegroups.com
When you call ele.json() or similar you get back the JS object rather than a JSON string so you can actually work with it.  If you have a JSON string you should use JSON.parse() or similar before passing it to cy.js. -M
--
You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-disc...@googlegroups.com.
To post to this group, send email to cytoscap...@googlegroups.com.
Visit this group at http://groups.google.com/group/cytoscape-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

sl yls

unread,
Nov 14, 2013, 12:33:40 PM11/14/13
to cytoscap...@googlegroups.com
Thanks for your reply, Max, The problem is that after I got the json string below:
jsonString='[{ data: {id:"oxid"},group:"nodes"}]'; 
Important Note: jsonString is catenated from several strings dynamically by php or python.
How can I use it in cy.load(), cy.load(jsonString) is not working.  Thanks.

You received this message because you are subscribed to a topic in the Google Groups "cytoscape-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cytoscape-discuss/MEC8WZLdrXQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cytoscape-disc...@googlegroups.com.

pis...@gmail.com

unread,
Aug 6, 2014, 10:00:08 AM8/6/14
to cytoscap...@googlegroups.com
you have to use

cy.load(JSON.parse(jsonString)); 
Reply all
Reply to author
Forward
0 new messages