Skip to content

Commit

Permalink
add exist key check to Add() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bwar committed Oct 20, 2019
1 parent 2f8103b commit 28faaad
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions CJsonObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ bool CJsonObject::AddEmptySubObject(const std::string& strKey)
m_strErrMsg = "not a json object! json array?";
return(false);
}
if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
{
m_strErrMsg = "key exists!";
return(false);
}
cJSON* pJsonStruct = cJSON_CreateObject();
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -121,6 +126,11 @@ bool CJsonObject::AddEmptySubArray(const std::string& strKey)
m_strErrMsg = "not a json object! json array?";
return(false);
}
if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
{
m_strErrMsg = "key exists!";
return(false);
}
cJSON* pJsonStruct = cJSON_CreateArray();
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -887,6 +897,11 @@ bool CJsonObject::Add(const std::string& strKey, const CJsonObject& oJsonObject)
m_strErrMsg = "not a json object! json array?";
return(false);
}
if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
{
m_strErrMsg = "key exists!";
return(false);
}
cJSON* pJsonStruct = cJSON_Parse(oJsonObject.ToString().c_str());
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -939,6 +954,11 @@ bool CJsonObject::Add(const std::string& strKey, const std::string& strValue)
m_strErrMsg = "not a json object! json array?";
return(false);
}
if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
{
m_strErrMsg = "key exists!";
return(false);
}
cJSON* pJsonStruct = cJSON_CreateString(strValue.c_str());
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -980,6 +1000,11 @@ bool CJsonObject::Add(const std::string& strKey, int32 iValue)
m_strErrMsg = "not a json object! json array?";
return(false);
}
if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
{
m_strErrMsg = "key exists!";
return(false);
}
cJSON* pJsonStruct = cJSON_CreateInt((uint64)iValue, -1);
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -1021,6 +1046,11 @@ bool CJsonObject::Add(const std::string& strKey, uint32 uiValue)
m_strErrMsg = "not a json object! json array?";
return(false);
}
if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
{
m_strErrMsg = "key exists!";
return(false);
}
cJSON* pJsonStruct = cJSON_CreateInt((uint64)uiValue, 1);
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -1062,6 +1092,11 @@ bool CJsonObject::Add(const std::string& strKey, int64 llValue)
m_strErrMsg = "not a json object! json array?";
return(false);
}
if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
{
m_strErrMsg = "key exists!";
return(false);
}
cJSON* pJsonStruct = cJSON_CreateInt((uint64)llValue, -1);
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -1103,6 +1138,11 @@ bool CJsonObject::Add(const std::string& strKey, uint64 ullValue)
m_strErrMsg = "not a json object! json array?";
return(false);
}
if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
{
m_strErrMsg = "key exists!";
return(false);
}
cJSON* pJsonStruct = cJSON_CreateInt(ullValue, 1);
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -1144,6 +1184,11 @@ bool CJsonObject::Add(const std::string& strKey, bool bValue, bool bValueAgain)
m_strErrMsg = "not a json object! json array?";
return(false);
}
if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
{
m_strErrMsg = "key exists!";
return(false);
}
cJSON* pJsonStruct = cJSON_CreateBool(bValue);
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -1185,6 +1230,11 @@ bool CJsonObject::Add(const std::string& strKey, float fValue)
m_strErrMsg = "not a json object! json array?";
return(false);
}
if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
{
m_strErrMsg = "key exists!";
return(false);
}
cJSON* pJsonStruct = cJSON_CreateDouble((double)fValue, -1);
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -1226,6 +1276,11 @@ bool CJsonObject::Add(const std::string& strKey, double dValue)
m_strErrMsg = "not a json object! json array?";
return(false);
}
if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
{
m_strErrMsg = "key exists!";
return(false);
}
cJSON* pJsonStruct = cJSON_CreateDouble((double)dValue, -1);
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -1267,6 +1322,11 @@ bool CJsonObject::AddNull(const std::string& strKey)
m_strErrMsg = "not a json object! json array?";
return(false);
}
if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
{
m_strErrMsg = "key exists!";
return(false);
}
cJSON* pJsonStruct = cJSON_CreateNull();
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -2128,6 +2188,7 @@ bool CJsonObject::Add(const CJsonObject& oJsonObject)
m_strErrMsg = "not a json array! json object?";
return(false);
}
}
cJSON* pJsonStruct = cJSON_Parse(oJsonObject.ToString().c_str());
if (pJsonStruct == NULL)
{
Expand Down Expand Up @@ -2189,6 +2250,7 @@ bool CJsonObject::Add(const std::string& strValue)
m_strErrMsg = "not a json array! json object?";
return(false);
}
}
cJSON* pJsonStruct = cJSON_CreateString(strValue.c_str());
if (pJsonStruct == NULL)
{
Expand Down

0 comments on commit 28faaad

Please sign in to comment.