05-03-2021 00:02
05-03-2021 00:02
I'm basing off one of the settings for my app on the Select component which is over here in the docs.
The problem I'm having is that in the companion, I can't seem to get the text value from the setting. It's parsing the JSON into the following stringified object:
{"values":[{"name":"Calories"}],"selected":[1]}I just want to get the "Calories" text, but any variation of JSON.parse(evt.newValue) is undefined.
I've tried JSON.parse(evt.newValue.values.name) and JSON.parse(evt.newValue.values[0].name) and nothing seems to work.
How would I get the string "Calories" from the parsed JSON?
Best Answer05-03-2021 00:13
05-03-2021 00:13
Never mind, I figured it out. This is what works:
data = JSON.parse(JSON.stringify(JSON.parse(evt.newValue).values[0].name));
Best Answer05-24-2021 07:58
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-24-2021 07:58
I don't think you need to double parse it.
JSON.parse(evt.newValue).values[0].name
Best Answer