I have a struct with a few string data members. Encoding this struct to a json string works perfectly fine with jsonEncode().
But when I try to convert this json string back to the struct using jsonDecode I get a warning message that the returned data type does not match my struct data type.
WARNING, 28/ctrl, mapping, Übergebener Datentyp entspricht nicht dem benötigten Typ 'BeccInfoWindowEntry',
I think the problem is that the jsonDecode() returns just a mapping and this, of course, can not be assigned to the struct.
Is there a way to tell jsonDecode() it should decode into and return the struct?
Decode json string to a struct
Search
-
- Posts: 373
- Joined: Tue Jan 15, 2019 3:12 pm
Re: Decode json string to a struct
There is no way to tell 'jsonDecode' to return the struct. I would extend the struct with a static 'fromJson' function to deserialize the json string and return a new struct with the data from the json string.