Пример #1
0
bool CJsonPacker::getItemBoolvalue(const char *pszKey, bool bDefaultValue)
{
    if (!isKeyValidate(pszKey, m_cValue) || !m_cValue[pszKey].isBool())
        return bDefaultValue;
    
    return m_cValue[pszKey].asBool();
}
Пример #2
0
double CJsonPacker::getItemFloatValue(const char *pszKey, double fDefaultValue)
{
    if (!isKeyValidate(pszKey, m_cValue) || !m_cValue[pszKey].isNumeric())
        return fDefaultValue;
    
    return m_cValue[pszKey].asDouble();
}
Пример #3
0
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();
 }
Пример #5
0
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];
}
Пример #6
0
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();
}
Пример #7
0
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;
}
Пример #8
0
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;
}