bool CJsonPacker::getItemBoolvalue(const char *pszKey, bool bDefaultValue) { if (!isKeyValidate(pszKey, m_cValue) || !m_cValue[pszKey].isBool()) return bDefaultValue; return m_cValue[pszKey].asBool(); }
double CJsonPacker::getItemFloatValue(const char *pszKey, double fDefaultValue) { if (!isKeyValidate(pszKey, m_cValue) || !m_cValue[pszKey].isNumeric()) return fDefaultValue; return m_cValue[pszKey].asDouble(); }
int CJsonPacker::getItemIntValue(const char *pszKey, int nDefaultValue) { if (!isKeyValidate(pszKey, m_cValue) || !m_cValue[pszKey].isNumeric()) return nDefaultValue; return m_cValue[pszKey].asInt(); }
const char * CSJsonDictionary::getItemStringValue(const char *pszKey) { if (!isKeyValidate(pszKey, m_cValue) || !m_cValue[pszKey].isString()) return NULL; return m_cValue[pszKey].asCString(); }
inline CSJson::Value * CJsonPacker::validateArrayItem(const char *pszArrayKey, int nIndex) { if (!isKeyValidate(pszArrayKey, m_cValue) && !m_cValue[pszArrayKey].isArray() && !m_cValue[pszArrayKey].isConvertibleTo(CSJson::arrayValue)) return NULL; if (!m_cValue[pszArrayKey].isValidIndex(nIndex)) return NULL; return &m_cValue[pszArrayKey]; }
const char * CJsonPacker::getItemStringValue(const char *pszKey) { // printf("root ppp %p",&m_cValue); if (!&m_cValue || !isKeyValidate(pszKey, m_cValue) || !m_cValue[pszKey].isString()) return NULL; return m_cValue[pszKey].asCString(); }
int CJsonPacker::getArrayItemCount(const char *pszArrayKey) { int nRet = 0; if (!isKeyValidate(pszArrayKey, m_cValue) || (!m_cValue[pszArrayKey].isArray() && !m_cValue[pszArrayKey].isObject() && !m_cValue[pszArrayKey].isConvertibleTo(CSJson::arrayValue) && !m_cValue[pszArrayKey].isConvertibleTo(CSJson::objectValue))) { nRet = 0; } else { CSJson::Value arrayValue = m_cValue[pszArrayKey]; nRet = arrayValue.size(); } return nRet; }
CJsonPacker * CJsonPacker::getSubDictionary(const char *pszKey) { CJsonPacker * pNewDictionary; if (!isKeyValidate(pszKey, m_cValue) || (!m_cValue[pszKey].isArray() && !m_cValue[pszKey].isObject() && !m_cValue[pszKey].isConvertibleTo(CSJson::arrayValue) && !m_cValue[pszKey].isConvertibleTo(CSJson::objectValue))) { pNewDictionary = NULL; } else { pNewDictionary = new CJsonPacker(); pNewDictionary->initWithValue(m_cValue[pszKey]); } return pNewDictionary; }