Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 5 Sequences & Scripting > 5.20 Object Oriented Programming

5.20.13 ToJson() / FromJson()

Scroll Prev Top Next More

DAQFactory supports easy persistence of object data in a json formatted string.  All user DAQFactory objects have a ToJson() function, which when called will return a string containing all the member variables in the object represented in json format.  The conversion is deep, so any member variables that are objects, or arrays, or arrays of objects will also be converted.  You can then save this string to a file or send it over the network or whatever.  You can also recreate the object by using the FromJson() function.  This exists in two forms, one as a member function of an existing object.  This allows you to restore data to an already instantiated object from a json string.  There is also a global FromJson() function that will instantiate the object for you.  See above note about accessing this version from within an object using the global. prefix: global.fromJson().

Note that for fromJson() to work properly, any referenced classes must have been defined already. ToJson() adds special fields that contain the name of the class to instantiate.  These are required to allow fromJson() to recreate the objects.  If that field does not exist, then a generic object is created with no associated class and no member functions.  This allows you to parse most JSON data from other sources.