[json.exception.type_error.302] type must be number, but is null when converting json to larger verctor #4832
Replies: 1 comment
-
never mind ... I finally found the answer, the web developer had failed to initialize one variable so there actually was a null data entry that should have been an empty string |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
the purpose of this code is to send a structure containing a vector as json to a cloud site where one may edit, insert or delete vector elements. the code works fine for edit or delete, but when a vector entry is inserted, the json to structure conversion fails when converting data into the vector with error [json.exception.type_error.302] type must be number, but is null
the really odd part, vector is allocated to be 15 elements, but by default we are only using 10. insert fails if the number of elements is larger than the original upload even though the code is creating new structures each time..
this error occurs in linux code that was built with gcc. I did not test with windows code
struct CONFIGURATION_DATA
{
std::vector Recipe; // { std::vector(MAX_RECIPES, { "","",0,0,"",0,"",0,"" }) }; // [MAX_RECIPES] ; //programable recipe sequence
};
struct CONFIGURATION
{
std::string stationId;
std::string type;
std::string timeStamp;
std::string uniqueId;
//struct SETTINGS settings;
//std::string Config_Name;
//std::vector Recipe{ std::vector(MAX_RECIPES,{"","",0,0,"",0,"",0,""}) }; // [MAX_RECIPES] ; //programable recipe sequence
CONFIGURATION_DATA configuration_data;
};
void to_json(json& j, const CONFIGURATION_DATA& A)
{
j = json{ { CONFIGURATION_DATA_RECIPE_TAG, A.Recipe}
};
}
void from_json(const json& j, CONFIGURATION_DATA& A)
{
A.Recipe.resize(MAX_RECIPES);
std::cout << "CONFIGURATION_DATA_RECIPE_TAG" << std::endl;
j.at(CONFIGURATION_DATA_RECIPE_TAG).get_to(A.Recipe); <<< code fails here if vector size is increased
std::cout << "CONFIGURATION_DATA_RECIPE_TAG exit" << std::endl;
}
void to_json(json& j, const CONFIGURATION& A)
{
j = json{ {CONFIGURATION_STATION_TAG,A.stationId},
{ CONFIGURATION_TYPE_TAG,A.type},
// { CONFIGURATION_TIMESTAMP_TAG,A.timeStamp },
// { CONFIGURATION_UNIQUE_ID_TAG,A.uniqueId},
{ CONFIGURATION_DATA_TAG,A.configuration_data}
};
}
void from_json(const json& j, CONFIGURATION& A)
{
//j.at(CONFIGURATION_STATION_TAG).get_to(A.stationId);
//j.at(CONFIGURATION_TYPE_TAG).get_to(A.type);
//j.at(CONFIGURATION_DATA_TAG).get_to(A.settings);
//j.at(CONFIGURATION_CONFIG_NAME_TAG).get_to(A.Config_Name);
//j.at(CONFIGURATION_DATA_TAG).get_to(A.Recipe);
std::cout << "CONFIGURATION_TIMESTAMP_TAG" << std::endl;
j.at(CONFIGURATION_TIMESTAMP_TAG).get_to(A.timeStamp);
std::cout << "CONFIGURATION_UNIQUE_ID_TAG" << std::endl;
j.at(CONFIGURATION_UNIQUE_ID_TAG).get_to(A.uniqueId);
std::cout << "CONFIGURATION_DATA_TAG" << std::endl;
j.at(CONFIGURATION_DATA_TAG).get_to(A.configuration_data);
std::cout << "CONFIGURATION_DATA_TAG exit" << std::endl;
}
bool ConfigurationFromJson(std::string* pmessage, SETTINGS* psettings, std::string* uniqueID_return)
{
int i;
CONFIGURATION configuration;
}
Beta Was this translation helpful? Give feedback.
All reactions