arduino-libraries / Arduino_JSON

Official JSON Library for Arduino
GNU Lesser General Public License v2.1
151 stars 60 forks source link

print myObject without quotation marks #9

Open BogdanPau opened 4 years ago

BogdanPau commented 4 years ago

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 commented 4 years ago

My response to https://github.com/bblanchon/ArduinoJson/issues/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