Skip to content

Parse Json Response #243

Closed Answered by Waboodoo
nirvine asked this question in Q&A
Oct 9, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Change the first line to the following:

const temperature = JSON.parse(response.body).result[0].temperature;

"result" is an array with one element, so you need to select the 0-th element from it before you try to access temperature.
The same should work for accessing the humidity:

const result = JSON.parse(response.body).result[0];
const temperature = result.temperature;
const humidity = result.humidity;

Also, you probably don't need the second line of your code (where you call setVariable), unless you actual have a global variable called "temperature" set up in the app which you are using somewhere else in the same shortcut (e.g. in a header) or in some other place. If you only need the …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@nirvine
Comment options

@Waboodoo
Comment options

Answer selected by nirvine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants