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 }}
Repository navigation
Incorrect behaviour of basic_json::count method #78
/// returns the number of occurrences of a key in an objectinline size_type count(typenameobject_t::key_type key) const
{
// return 0 for all nonobject typesreturn (m_type == value_t::object) ? m_value.object->count(key) : 0;
}
we should got "2" in program output. By I got "1".
No, 1 is the correct result, because an object is a mapping of keys to values. Hence, a key can only occur once on the mapping.
The standard nlohmann::json uses std::map to implement JSON's object. You could, if you like, use std::multi_map instead. Then, the result would indeed be 2 (to the price that the container is not compliant JSON any more).
Activity
nlohmann commentedon May 30, 2015
No,
1is the correct result, because an object is a mapping of keys to values. Hence, a key can only occur once on the mapping.The standard
nlohmann::jsonusesstd::mapto implement JSON's object. You could, if you like, usestd::multi_mapinstead. Then, the result would indeed be2(to the price that the container is not compliant JSON any more).drewpts commentedon May 30, 2015
I understood. Sorry.
nlohmann commentedon May 30, 2015
No worries!