/** * 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 ); }
CPLJSONObject GlEditLayerOverlay::style(enum ngsEditStyleType type) const { if(EST_POINT == type) { return m_pointStyle->save(); } if(EST_LINE == type) { return m_lineStyle->save(); } if(EST_FILL == type) { return m_fillStyle->save(); } if(EST_CROSS == type) { return m_crossStyle->save(); } return CPLJSONObject(); }
/** * \brief Get json object children. * * This function is useful when keys is not know and need to * iterate over json object items and get keys and values. * * @return Array of CPLJSONObject class instance. * * @since GDAL 2.3 */ std::vector<CPLJSONObject> CPLJSONObject::GetChildren() const { std::vector<CPLJSONObject> aoChildren; if(nullptr == m_poJsonObject || json_object_get_type( TO_JSONOBJ(m_poJsonObject) ) != json_type_object ) { return aoChildren; } json_object_iter it; it.key = nullptr; it.val = nullptr; it.entry = nullptr; json_object_object_foreachC( TO_JSONOBJ(m_poJsonObject), it ) { aoChildren.push_back(CPLJSONObject(it.key, it.val)); }
/** * Get json document root object * @return CPLJSONObject class instance * * @since GDAL 2.3 */ CPLJSONObject CPLJSONDocument::GetRoot() { if( nullptr == m_poRootJsonObject ) { m_poRootJsonObject = json_object_new_object(); } if( json_object_get_type( TO_JSONOBJ(m_poRootJsonObject) ) == json_type_array ) { return CPLJSONArray( "", m_poRootJsonObject ); } else { return CPLJSONObject( "", m_poRootJsonObject ); } }