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
I just wrote two custom classes based on nlohmann::json: class Cookie : public nlohmann::json <- this can handle cookies, chops up cookie strings from headers, etc... class JsonFile : public nlohmann::json <- this is nothing else but the json class joined up with a fstream to make easier to load and save json from file.
My problem is, if I create a Cookie like Cookie A1("A1=d=AQABBN3h6GUCECMYqmLClG1pK2uiuaCh0xoFEgABCAEq6mUTZutMb2UBAiAAAAcI3OHoZXSoivI&S=AQAAAqvfHaGFJkLfQ07HNDr2tH0;Expires=Thu, 6 Mar 2025 213629 GMT;"); and I try to pass it into a JsonFile like
it says "terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::type_error' what(): [json.exception.type_error.302] type must be string, but is object".
The Cookie works fine, chopping and parsing are done and if I do it like this cJsonFile["Cookies"]["A1"] = A1.dump(); and it works as well. ChatGPT suggested to me that I should write an operator Cookie& operator=(const nlohmann::json& other) and pass the things trough here but this will be not triggered with cJsonFile["Cookies"]["A1"] = A1;.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I just wrote two custom classes based on nlohmann::json:
class Cookie : public nlohmann::json
<- this can handle cookies, chops up cookie strings from headers, etc...class JsonFile : public nlohmann::json
<- this is nothing else but the json class joined up with a fstream to make easier to load and save json from file.My problem is, if I create a Cookie like
Cookie A1("A1=d=AQABBN3h6GUCECMYqmLClG1pK2uiuaCh0xoFEgABCAEq6mUTZutMb2UBAiAAAAcI3OHoZXSoivI&S=AQAAAqvfHaGFJkLfQ07HNDr2tH0;Expires=Thu, 6 Mar 2025 213629 GMT;");
and I try to pass it into aJsonFile
likeFileHandlers::JsonFile cJsonFile(cookieJson); cJsonFile["Cookies"]["A1"] = A1;
it says "terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::type_error' what(): [json.exception.type_error.302] type must be string, but is object".
The Cookie works fine, chopping and parsing are done and if I do it like this
cJsonFile["Cookies"]["A1"] = A1.dump();
and it works as well. ChatGPT suggested to me that I should write an operatorCookie& operator=(const nlohmann::json& other)
and pass the things trough here but this will be not triggered withcJsonFile["Cookies"]["A1"] = A1;
.Has anyone encountered this problem?
Beta Was this translation helpful? Give feedback.
All reactions