FromJSON() Crash on String Array


burt4munger

Recommended Posts

Hi,

We are trying to use the FromJSON() function on an object to read in the results from an API and utilize the data in DAQFactory. The data is in the form of an array of results (example below):

 [
   {
     "time": 1689202773000,
     "frequency": 0,
     "temperature": 24.113449096679688,
     "density": 1.0002
   },
   {
     "time": 1689204584000,
     "frequency": 0,
     "temperature": 23.971923828125,
     "density": 1.0003
   },
   {
     "time": 1689206446000,
     "frequency": 0,
     "temperature": 23.421836853027344,
     "density": 1.0004
   },
   {
     "time": 1689207479000,
     "frequency": 1376.7645263671875,
     "temperature": 23.03997802734375,
     "density": 1.0013
   }
 ]

So far whenever we try to apply FromJSON() on this sort of an array of data, DAQFactory exits immediately (the Windows Application event log records it as "Faulting module name: ntdll.dll, version: 10.0.19041.3155"). If we run FromJSON() on just one of the individual results by pulling it out of the array, it works and we can view the properties. I know everything is an array in DAQFactory, but is there something special we have to do to get FromJSON() to work with a JSON array? (This is in DAQFactory 19.1 Build 2366.) Thanks!

 

Link to comment
Share on other sites

FromJson is limited to existing classes and requires the specification of the class name for each object.  This is something we are hoping to improve upon, probably in the next release, if not shortly after.  For now, you will have to split the array and process each element.  It's pretty easy to split the array since you can just search for { and }.  Once you have it down to a string like:

{"time": 1689202773000,"frequency": 0,"temperature": 24.113449096679688,"density": 1.0002}

You just need to define a class name in there.  So, first you need to declare a class.  It can be empty:

class CData
endclass

Then inject the class name specifier in your string:

{"_ClassName" : "CData", "time": 1689202773000,"frequency": 0,"temperature": 24.113449096679688,"density": 1.0002}

Now you can use fromJson() and it will work.  Repeat for each object.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.