MCPcopy Create free account
hub / github.com/Bwar/CJsonObject / Replace

Method Replace

CJsonObject.cpp:1641–1688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1639}
1640
1641bool CJsonObject::Replace(const std::string& strKey, const CJsonObject& oJsonObject)
1642{
1643 cJSON* pFocusData = NULL;
1644 if (m_pJsonData == NULL)
1645 {
1646 pFocusData = m_pExternJsonDataRef;
1647 }
1648 else
1649 {
1650 pFocusData = m_pJsonData;
1651 }
1652 if (pFocusData == NULL)
1653 {
1654 m_strErrMsg = "json data is null!";
1655 return(false);
1656 }
1657 if (pFocusData->type != cJSON_Object)
1658 {
1659 m_strErrMsg = "not a json object! json array?";
1660 return(false);
1661 }
1662 cJSON* pJsonStruct = cJSON_Parse(oJsonObject.ToString().c_str(), &mc_pError);
1663 if (pJsonStruct == NULL)
1664 {
1665 m_strErrMsg = std::string("prase json string error at ") + mc_pError;
1666 return(false);
1667 }
1668 cJSON_ReplaceItemInObject(pFocusData, strKey.c_str(), pJsonStruct);
1669 if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) == NULL)
1670 {
1671 return(false);
1672 }
1673#if __cplusplus < 201101L
1674 std::map<std::string, CJsonObject*>::iterator iter = m_mapJsonObjectRef.find(strKey);
1675#else
1676 auto iter = m_mapJsonObjectRef.find(strKey);
1677#endif
1678 if (iter != m_mapJsonObjectRef.end())
1679 {
1680 if (iter->second != NULL)
1681 {
1682 delete (iter->second);
1683 iter->second = NULL;
1684 }
1685 m_mapJsonObjectRef.erase(iter);
1686 }
1687 return(true);
1688}
1689
1690#if __cplusplus < 201101L
1691bool CJsonObject::ReplaceWithMove(const std::string& strKey, CJsonObject& oJsonObject)

Callers 1

mainFunction · 0.80

Calls 10

cJSON_ParseFunction · 0.85
cJSON_GetObjectItemFunction · 0.85
cJSON_CreateStringFunction · 0.85
cJSON_CreateIntFunction · 0.85
cJSON_CreateBoolFunction · 0.85
cJSON_CreateDoubleFunction · 0.85
cJSON_ReplaceItemInArrayFunction · 0.85
cJSON_GetArrayItemFunction · 0.85
ToStringMethod · 0.80

Tested by

no test coverage detected