Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print myObject without quotation marks #9

Open
BogdanPau opened this issue Jun 12, 2020 · 1 comment
Open

print myObject without quotation marks #9

BogdanPau opened this issue Jun 12, 2020 · 1 comment

Comments

@BogdanPau
Copy link

Hi guys,
I've been trying for a long time and online research for something that sounds quite basic.
I'm using this library in my Arduino project with ESP8266 NodeMCU LUA chip.
I'm fetching successfully the GET HTTP with an API I'm connecting to.
To API returning the JSON, example:
JSON object = {"meta":{"timestamp":"2020-06-12T19:46:07.708066Z","stations_updated":"2019-06-09"},"altimeter":{"repr":"Q1008","value":1008,"spoken":"one zero zero eight"},"clouds":[{"repr":"FEW034","type":"FEW","altitude":34,"modifier":null,"direction":null}],"flight_rules":"VFR","other":[],"sanitized":"LRCL 121930Z 31003KT 9999 FEW034 19/17 Q1008 R07/19//95","visibility":{"repr":"9999","value":9999,"spoken":"nine nine nine nine"},"wind_direction":{"repr":"310","value":310,"spoken":"three one zero"},"wind_gust":null,"wind_speed":{"repr":"03","value":3,"spoken":"three"},"wx_codes":[],"raw":"LRCL 121930Z 31003KT 9999 FEW034 19/17 Q1008 R07/19//95","station":"LRCL","time":{"repr":"121930Z","dt":"2020-06-12T19:30:00Z"},"remarks":"R07/19//95","dewpoint":{"repr":"17","value":17,"spoken":"one seven"},"remarks_info":{"dewpoint_decimal":null,"temperature_decimal":null},"runway_visibility":[],"temperature":{"repr":"19","value":19,"spoken":"one nine"},"wind_variable_direction":[],"units":{"altimeter":"hPa","altitude":"ft","temperature":"C","visibility":"m","wind_speed":"kt"}}

Then with the library parser I can take the objects I wish.
The problem is that when I print one of the objects out, let say:
Serial.println(myObject["meta"]["timestamp"]);
I get this result:
Timestamp: "2020-06-12T19:46:07.708066Z"
With the " " (quotation marks) and those are giving me an headache to get rid off in efficient way.
I know I can store the myObject in a string and then do String.replace(""",""). But if I'm taking a lot of values from the JSON and clean them each time like this I'm just making super excessive code.
Is there any efficient way to clean the JSON from those quotation marks?
I acknowledge they might be from the returned API response, as it does has them..

Thanks,
Bogdan

@bblanchon
Copy link

My response to bblanchon/ArduinoJson#1294:

Hi Bogan,

I think the following line should work with both libraries:

Serial.println((const char*)doc["meta"]["timestamp"]);

See also:

Best regards,
Benoit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants