| 1636 | } |
| 1637 | |
| 1638 | bool CJsonObject::Delete(const std::string& strKey) |
| 1639 | { |
| 1640 | cJSON* pFocusData = NULL; |
| 1641 | if (m_pJsonData == NULL) |
| 1642 | { |
| 1643 | pFocusData = m_pExternJsonDataRef; |
| 1644 | } |
| 1645 | else |
| 1646 | { |
| 1647 | pFocusData = m_pJsonData; |
| 1648 | } |
| 1649 | if (pFocusData == NULL) |
| 1650 | { |
| 1651 | m_strErrMsg = "json data is null!"; |
| 1652 | return(false); |
| 1653 | } |
| 1654 | if (pFocusData->type != cJSON_Object) |
| 1655 | { |
| 1656 | m_strErrMsg = "not a json object! json array?"; |
| 1657 | return(false); |
| 1658 | } |
| 1659 | cJSON_DeleteItemFromObject(pFocusData, strKey.c_str()); |
| 1660 | #if __cplusplus < 201101L |
| 1661 | std::map<std::string, CJsonObject*>::iterator iter = m_mapJsonObjectRef.find(strKey); |
| 1662 | #else |
| 1663 | auto iter = m_mapJsonObjectRef.find(strKey); |
| 1664 | #endif |
| 1665 | if (iter != m_mapJsonObjectRef.end()) |
| 1666 | { |
| 1667 | if (iter->second != NULL) |
| 1668 | { |
| 1669 | delete (iter->second); |
| 1670 | iter->second = NULL; |
| 1671 | } |
| 1672 | m_mapJsonObjectRef.erase(iter); |
| 1673 | } |
| 1674 | m_pKeyTravers = pFocusData; |
| 1675 | return(true); |
| 1676 | } |
| 1677 | |
| 1678 | bool CJsonObject::Replace(const std::string& strKey, const CJsonObject& oJsonObject) |
| 1679 | { |
nothing calls this directly
no test coverage detected