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

Decoding JSON received with Serial #422

Closed
marlonrettore opened this issue Jan 18, 2017 · 3 comments
Closed

Decoding JSON received with Serial #422

marlonrettore opened this issue Jan 18, 2017 · 3 comments
Labels
bug v5 ArduinoJson 5

Comments

@marlonrettore
Copy link

Good morning mate,

I'm getting a JSOn via Serial from another arduino, how do I do the decoding of this JSON, I could not do it. Could you give me an example of a serial JSON reception of his decoding?

Thanks, I'm waiting

@bblanchon
Copy link
Owner

Hello @marlonrettore,

It's a bug.
I'm calling Stream.read() which doesn't take the timeout into account.

Thanks for reporting this.

Regards,
Benoit

@bblanchon bblanchon added the bug label Jan 18, 2017
@marlonrettore
Copy link
Author

Good morning mate

Would it look like this?

char json[] = Stream.read();

StaticJsonBuffer<200> jsonBuffer;

JsonObject& root = jsonBuffer.parseObject(json);

if (!root.success())
{
Serial.println("parseObject() failed");
return;
}
const char* sensor = root["sensor"];
long time = root["time"];
double latitude = root["data"][0];
double longitude = root["data"][1];

@bblanchon
Copy link
Owner

Hello @marlonrettore,

I'll be even simpler, as no char[] is required:

JsonObject& root = jsonBuffer.parseObject(Serial);

But you'll need a bigger JsonBuffer to hold the copy of the input.

It's already fixed in the issue422 branch if you want to try.

bblanchon added a commit that referenced this issue Jan 22, 2017
Repository owner locked and limited conversation to collaborators Sep 21, 2018
@bblanchon bblanchon added the v5 ArduinoJson 5 label Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug v5 ArduinoJson 5
Projects
None yet
Development

No branches or pull requests

2 participants