/** * Add new key - value pair to json object. * @param osName Key name. * @param oValue Json object value. * * @since GDAL 2.3 */ void CPLJSONObject::Add(const std::string &osName, const CPLJSONObject &oValue) { std::string objectName; CPLJSONObject object = GetObjectByPath( osName, objectName ); if( object.IsValid() && json_object_get_type(TO_JSONOBJ(object.m_poJsonObject)) == json_type_object ) { json_object_object_add( TO_JSONOBJ(object.GetInternalHandle()), objectName.c_str(), json_object_get( TO_JSONOBJ(oValue.GetInternalHandle()) ) ); } }
/** * Delete json object by key. * @param osName Key name. * * @since GDAL 2.3 */ void CPLJSONObject::Delete(const std::string &osName) { std::string objectName; CPLJSONObject object = GetObjectByPath( osName, objectName ); if( object.IsValid() ) { json_object_object_del( TO_JSONOBJ(object.GetInternalHandle()), objectName.c_str() ); } }
/** * Add new key - value pair to json object. * @param osName Key name. * @param bValue Boolean value. * * @since GDAL 2.3 */ void CPLJSONObject::Add(const std::string &osName, bool bValue) { std::string objectName; CPLJSONObject object = GetObjectByPath( osName, objectName ); if( object.IsValid() && json_object_get_type(TO_JSONOBJ(object.m_poJsonObject)) == json_type_object ) { json_object *poVal = json_object_new_boolean( bValue ); json_object_object_add( TO_JSONOBJ(object.GetInternalHandle()), objectName.c_str(), poVal ); } }
/** * Get value by key. * @param osName Key name. * @return Json object. * * @since GDAL 2.3 */ CPLJSONObject CPLJSONObject::GetObj(const std::string &osName) const { std::string objectName; CPLJSONObject object = GetObjectByPath( osName, objectName ); if( object.IsValid() ) { json_object* poVal = nullptr; if(json_object_object_get_ex( TO_JSONOBJ(object.GetInternalHandle()), objectName.c_str(), &poVal ) ) { return CPLJSONObject( objectName, poVal ); } } return CPLJSONObject( "", nullptr ); }
/** * Add new key - value pair to json object. * @param osName Key name. * @param pszValue String value. * * @since GDAL 2.3 */ void CPLJSONObject::Add(const std::string &osName, const char *pszValue) { if(nullptr == pszValue) { return; } std::string objectName; CPLJSONObject object = GetObjectByPath( osName, objectName ); if( object.IsValid() && json_object_get_type(TO_JSONOBJ(object.m_poJsonObject)) == json_type_object ) { json_object *poVal = json_object_new_string( pszValue ); json_object_object_add( TO_JSONOBJ(object.GetInternalHandle()), objectName.c_str(), poVal ); } }
CPL_C_END /** * Add new key - value pair to json object. * @param osName Key name. * @param dfValue Double value. * * @since GDAL 2.3 */ void CPLJSONObject::Add(const std::string &osName, double dfValue) { std::string objectName; CPLJSONObject object = GetObjectByPath( osName, objectName ); if( object.IsValid() && json_object_get_type(TO_JSONOBJ(object.m_poJsonObject)) == json_type_object ) { json_object *poVal = json_object_new_double_with_significant_figures( dfValue, -1 ); json_object_object_add( TO_JSONOBJ(object.GetInternalHandle()), objectName.c_str(), poVal ); } }