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

Boolean in Json #13

Open
kovacskor opened this issue Dec 4, 2022 · 4 comments
Open

Boolean in Json #13

kovacskor opened this issue Dec 4, 2022 · 4 comments

Comments

@kovacskor
Copy link

Hi Guys,

I started to use your library, I like is a lot because of it's simplicity and lightness.
I've encountered an issue though, when I need to deserialize a json and retrieve a bool value it seems not to work.
Example json:
{"_id":"637a8b27171c8e5a9","name":"somename","type":"a4","apikey":"someapikey","deviceid":"a48003cb","createdAt":"2022-11-20T20:16:35.783Z","online":true}

example code:
void setup() {
Serial.begin(115200);
String test_json = "{"_id":"637a8b27171c8e5a9","name":"somename","type":"a4","apikey":"someapikey","deviceid":"a48003cb","createdAt":"2022-11-20T20:16:35.783Z","online":true}";
delay(5000);

Serial.println(jsonExtract(test_json, "name")); // result is somename which is good :)
Serial.println(jsonExtract(test_json, "online"));
}

// result is {"_id":"637a8b27171c8e5a9","name":"somename","type":"a4","apikey":"someapikey","deviceid":"a48003cb","createdAt":"2022-11-20T20:16:35.783Z","online":

I was in a hurry so what I did to resolve it is added a few lines to jsonlib.cpp from line 120:

// bool
else if(json.substring(start, start + 4) == "true"){
stop = start + 4;
}
else if (json.substring(start, start + 5) == "false"){
stop = start + 5;
}

This way it interprets bool now.

Please let me know if there is an another way to do that.

Thanks in advance,
Kornel

@wyojustin
Copy link
Member

Hey! Glad you are getting some use of jsonlib. I'm glad you found a work around! That's the best I can offer right now as I've not looked at this code in a couple years.

Justin

@kovacskor
Copy link
Author

Would you be interested to include this to your lib? I would make a pull requests than.

@wyojustin
Copy link
Member

wyojustin commented Dec 5, 2022 via email

@wyojustin
Copy link
Member

wyojustin commented Dec 5, 2022 via email

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