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
Describe what you want to achieve.
Trying to find object(s) that matches the search criteria
Describe what you tried.
Do I need to write a search on each key value and loop over all the objects in the vector to find the match? That seems too expensive. Any suggestions? I should be able to search on all the keys and return the matching objects.
classperson {
public:
std::string name;
std::string address;
int age;
};
voidto_json(json& j, const person& p) {
j = json{ {"name", p.name}, {"address", p.address}, {"age", p.age} };
}
voidfrom_json(const json& j, person& p) {
if (j.contains("name")) p.name = j.at("name").get<std::string>();
if (j.contains("address")) p.address = j.at("address").get<std::string>();
if (j.contains("age")) p.age = j.at("age").get<int>();
}
intmain()
{
std::vector<ns::person> persons;
// convert to JSON: copy each value into the JSON object
ifstream inputFile("input/person.json");
json j;
ns::person person;
try {
j = json::parse(inputFile, NULL, true);// false to get rid of errorif (j.is_discarded()) {
cout << "error";
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
for (int i = 0; i < j.size(); i++)
{
std::cout << j.at(i)<<"\n";
person = j.at(i);
persons.push_back(person);
}
//ask user for search criteria// loop over all the objects and return the match?
}
Describe which system (OS, compiler) you are using.
Describe which version of the library you are using (release version, develop branch).
The text was updated successfully, but these errors were encountered:
Trying to find object(s) that matches the search criteria
Do I need to write a search on each key value and loop over all the objects in the vector to find the match? That seems too expensive. Any suggestions? I should be able to search on all the keys and return the matching objects.
Describe which system (OS, compiler) you are using.
Describe which version of the library you are using (release version, develop branch).
The text was updated successfully, but these errors were encountered: