You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Serialization of array of not same model items #712
When trying to serialize json string that contains array of elements that have a different model, serialization throws first time it encounters a different type for the same key. Simplified example of my situation is below:
So because I know that the value for id should be int but is sometimes saved as a string I just call this function when reading the value in from_json function.
Activity
nlohmann commentedon Aug 26, 2017
There is no problem with this. This program parses your input and prints it:
Output:
What is your error message?
Haaxor1689 commentedon Aug 26, 2017
So I've solved this issue now. I was getting the error in
from_jsonmethod that converts that json to my model class.Solution was pretty straightforward once I found out that I can check the type of data that lies in json type on runtime with this simple function:
So because I know that the value for id should be int but is sometimes saved as a string I just call this function when reading the value in
from_jsonfunction.