ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting text to an array (JSON) or passing in different datatype objects to a function

Solved!
Go to solution

Using the JSONtext add-on with the sample text provided, I have quick success looping through each "methods" object, and displaying key value of each one. I plan on passing these arrays into .NET Framework methods later on.

 

I have two options:

1. How can I pass in a datatype to a function in labview.

2. Or, How can I convert a string "[ 2, 4, ..., 6]" for example into a LabVIEW array

 

Download All
0 Kudos
Message 1 of 6
(1,993 Views)

If you are not 100% sure how cluster or the read json looks like in advance, consider using something like here:https://pettaa123.github.io/labview-blog/2023/01/09/Set-Cluster-Elements-by-Ref-from-JSON.html

Actor Framework
0 Kudos
Message 2 of 6
(1,956 Views)

In JavaScript converting a JSON string to an actual array is extremely easy:

var stringArray = "[1,2,3]";
var actualArray = JSON.parse(stringArray);
console.log(actualArray); // Output: [1, 2, 3]

 Is there way to do it quick and easy like this in labVIEW?

0 Kudos
Message 3 of 6
(1,914 Views)
Solution
Accepted by elibarber

Hi elibarber,

 

Use the malleable VI "Find Item (as LVtype).vim" to directly specify the data type:

 

raphschru_0-1710254189207.png

 

 

For your use case, you can also use "Find Multiple Items (as LVtype).vim":

 

raphschru_2-1710254366718.png

 

Regards,

Raphaël.

0 Kudos
Message 4 of 6
(1,905 Views)

@raphschru wrote:

Use the malleable VI "Find Item (as LVtype).vim" to directly specify the data type:


Note:  This VIM is part of the JSONtext Toolkit by JDP Science.  I use this library in almost all of my applications anymore.  It is an amazing toolkit.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 6
(1,895 Views)

That worked! thank you!

0 Kudos
Message 6 of 6
(1,885 Views)