Help needed with reading a Json array from ThingSpeak

Hello all,

I'm trying to create a simple program to read the api data from ThingSpeak.


This is what the data looks like, I only need the last two values , field1 and field2.

Is the code. I am however getting "not found" for both values.

My suspicion is the reader is only taking the first field1 and field2 from the api but I only need the end part.

I've looked all over at things such as splitting the data but none of the online demos seem to help.

Any help would be most appreciated as I am almost pulling my hair out at this point.

You could work with dictionary blocks. Initilalize local json to create an empty json

image

With this extension:
https://community.appinventor.mit.edu/t/extension-json-decode-jsonpath-get-the-value-easily/43931/2

2 Likes

Hello,
Thanks for the reply

I tried this but I now seem to get stuck on it reading the first fields still. In this case 0.0.

How do I "skip ahead" or just read the last field1 and field2 data please?

Try this way,

If you data return from the api is consistent, then just split the json at the [, remove the ]} at the end, from the Web component use the jsonDecode block to convert to a list, extract the data for field1 and field2 from the list.

image

Hey that worked thanks!

but now I have the [""] included with the number. Is there a way to clear this? I plan to use the global variable later to plot a point on a map in real time but the brackets and quotation marks would mess it up i think.

Thanks for the reply!

I might try this method, if I can't get a smooth way to record and display the data.

3 Likes

Almost there! I still have the [ ] though. Do i just stack replace all text on top of each other?

Also side note, is the variable storing any white spaces/blanks? Or does this method remove the characters entirely?

1 Like

The variable will store what ever the value is in field1 and field2, if there are any blanks or white spaces it will be stored

Thanks for all your help.

You help prevent the loss of a lot of hair.

This is what i ended up doing in the end. Not sure if it's the most efficient but it works haha.

1 Like

Maybe this also do the same thing

2 Likes