04-28-2020 04:12 PM
Hello,
I am trying to add a piece of data from a Json string which I have parsed successfully. Howhen When I try to put the data in an Arry using for loop, the built array gives all elements as the same number.
I have been trying to fix this since two days and have also gone through many threads but could not get help.
The o/p arrays looks like
My VI for array looks like this.
I have tried working with Auto indexing as well as shift register, but nothing seems to work. Iit will be really helpful if someone can guide me through it.
Thanks
Solved! Go to Solution.
04-28-2020 04:38 PM
Your for loop input has only one value. How are you expecting to get different values ever?
Maybe you want to build the array in a shift register anchored on the toplevel while loop?
(It's is hard to give more target advice if you only show us a tiny piece of a diagram picture. Attach your VI! )
04-28-2020 04:41 PM
The problem is that your data changes outside the loop. The loop will only grab the data from there once, and work with that value. The thing that changes the values has to be inside your loop.
04-29-2020 02:42 AM
If you want something to change inside a loop, you'll have to change it inside a loop ...
In pseudo code, you're writing:
array y
int x = 3370
for (i=0;i<4000;i++)
{
y.add(x)
}
Now what would be added to the array y?
04-29-2020 08:38 AM
Hello,
Thank you all for the prompt response.
Here is the attached VI. I am trying to build an array with data from my Json string.
04-29-2020 11:20 AM - edited 04-29-2020 11:27 AM
Maybe something like that?
Of course of you want to only keep the latest 500, you need a little more code. Currently, you will eventually run out of memory if the array grows without bounds.
You would do something similar th the entry ID (not shown)
You might even want to bundle the ID and value into a cluster and create an array of clusters.
Your string parsing looks a bit convoluted. Do you have an example string? Looks like you dealing with time quanta (hours, minutes, seonds, etc.), so why is there orange? Aren't these integers?I am sure there is a much simpler way.
04-29-2020 12:08 PM
Hello Altenbach,
Let me try with the feedback node.
This is my Json string (
https://api.thingspeak.com/channels/1038537/feeds.json?api_key=S2Z7WRAMR790XII5&results=2
which I have parsed. I had to extract all the values from the string and then convert them into numeric.
I am sure there is a very simple way but I am very new to Labview and could just build whatever i got from the forums.
Thanks for the example, let me try and get back here.
Thanks
04-29-2020 12:18 PM
The feedback element works perfectly the way I want it. Thank you Altenbach.
04-29-2020 12:50 PM
Here's how to parse the time string.
04-29-2020 12:59 PM
This is really simple actually.
I tried with scan from string function and asked it to scan timestamp, but as you may have noticed the time stamp had zone and time separator, due to which it never worked for me.
But your solution is brilliant, thank you so much.