Decode json string to a struct

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
Search

Post Reply
2 posts • Page 1 of 1
mmarchha
Posts: 6
Joined: Mon May 16, 2011 8:33 am

Decode json string to a struct

Post by mmarchha »

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?

gschijndel
Posts: 373
Joined: Tue Jan 15, 2019 3:12 pm

Re: Decode json string to a struct

Post by gschijndel »

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.

Post Reply
2 posts • Page 1 of 1