取消
显示结果 
搜索替代 
您的意思是: 

cluster to a array

已解决!
转到解答

Hello,

So i have a cluster imported from a JSON file, the cluster is organized like below(left one) which lead to a error when i try to use cluster to array, so my question is is there a easy way to parse that cluster like the right one?

 

seems that inner cluster need to have same variable quantities(but not necessary for same variable name) like the right one?

 

ericyuan_1-1593675072806.png

 

 

0 项奖励
1 条消息(共 9 条)
3,743 次查看

Hi Eric,

 

You can use Variant To Data to convert a cluster to an array of variants.  Each element of the array then contains one field from the cluster.  In this case you would use it twice: firstly to convert the original cluster to an array of "Person" clusters, then within a loop for each of these clusters to extract the Name and Age fields and convert to strings.

 

This method relies on knowing the data type of your fields but since you are showing yours as all strings, this should not be a problem.

 

Cluster to array.png

PsyenceFact

0 项奖励
2 条消息(共 9 条)
3,719 次查看

@ericyuan wrote:

seems that inner cluster need to have same variable quantities(but not necessary for same variable name) like the right one?

 


Elements of an array are all the same, so to convert a cluster to an array, all cluster elements need to be the same.

 

Cluster to Array.PNG

 

This is a solution to what you've asked for.

 

It probably doesn't solve your real problem.

 

In reality, you probably get an arbitrary number of persons, with any number of properties that are or aren't there? You'll probably want to ship the cluster (as it's fixed at compile time), and find a way to convert the JSON to an array (or map) of maps.

 

 

0 项奖励
3 条消息(共 9 条)
3,718 次查看

What do you want the Output to be? An Array of clusters? an Array of Strings?

 

Is every instance of the cluster the same?

---------------------------------------------------

Projektingenieur
Restbust, Simulations and HiL development
Custom Device Developer
0 项奖励
4 条消息(共 9 条)
3,676 次查看

hey PsyenceFact

that seems to be the right solution, thanks for your help, I will have a look check and get back to you soon

0 项奖励
5 条消息(共 9 条)
3,627 次查看

I want to convert them to a array of a string. the instance of the cluster are not quite the same but they do have some same items.

0 项奖励
6 条消息(共 9 条)
3,625 次查看

that's just a simple example for what i really want to do, my real idea is trying to minimize the time that i spend on developing the test rig from project to project by simply write a JSON file and get the test items and then execute the individual test case for each of the items.

Attached is the json file that i want to parse, and luckily by using this parse JSON to cluster. I was able to get a cluster, so my next step is going to parse that cluster into a array, so that I can do test based on the  category of each test case.

 

 

0 项奖励
7 条消息(共 9 条)
3,617 次查看
解答
已被主题作者 ericyuan 接受

The standard LabVIEW JSON functionality is not very flexible, especially when your JSON can't be shoehorned into a rigid array of clusters.  Try using JSONtext instead to turn your JSON to an array of subJSON items, then do different things based on what type of item is:

 

JSONtext.png

 

BTW: I see that that your JSON is using strings rather than numbers ("0.05" rather than 0.05).  You should use proper numbers.

0 项奖励
8 条消息(共 9 条)
3,611 次查看

that's AWESOME, thanks for share that information, that should definitely save my workload.

 

 

0 项奖励
9 条消息(共 9 条)
3,566 次查看