| 334 | } |
| 335 | |
| 336 | std::string CJsonObject::operator()(const std::string& strKey) const |
| 337 | { |
| 338 | cJSON* pJsonStruct = NULL; |
| 339 | if (m_pJsonData != NULL) |
| 340 | { |
| 341 | if (m_pJsonData->type == cJSON_Object) |
| 342 | { |
| 343 | pJsonStruct = cJSON_GetObjectItem(m_pJsonData, strKey.c_str()); |
| 344 | } |
| 345 | } |
| 346 | else if (m_pExternJsonDataRef != NULL) |
| 347 | { |
| 348 | if(m_pExternJsonDataRef->type == cJSON_Object) |
| 349 | { |
| 350 | pJsonStruct = cJSON_GetObjectItem(m_pExternJsonDataRef, strKey.c_str()); |
| 351 | } |
| 352 | } |
| 353 | if (pJsonStruct == NULL) |
| 354 | { |
| 355 | return(std::string("")); |
| 356 | } |
| 357 | if (pJsonStruct->type == cJSON_String) |
| 358 | { |
| 359 | return(pJsonStruct->valuestring); |
| 360 | } |
| 361 | else if (pJsonStruct->type == cJSON_Int) |
| 362 | { |
| 363 | char szNumber[128] = {0}; |
| 364 | if (pJsonStruct->sign == -1) |
| 365 | { |
| 366 | if (pJsonStruct->valueint <= (int64)INT_MAX && (int64)pJsonStruct->valueint >= (int64)INT_MIN) |
| 367 | { |
| 368 | snprintf(szNumber, sizeof(szNumber), "%d", (int32)pJsonStruct->valueint); |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | #if LLONG_MAX==LLONG_MAX |
| 373 | snprintf(szNumber, sizeof(szNumber), "%ld", (int64)pJsonStruct->valueint); |
| 374 | #else |
| 375 | snprintf(szNumber, sizeof(szNumber), "%lld", (int64)pJsonStruct->valueint); |
| 376 | #endif |
| 377 | } |
| 378 | } |
| 379 | else |
| 380 | { |
| 381 | if ((uint64)pJsonStruct->valueint <= (uint64)UINT_MAX) |
| 382 | { |
| 383 | snprintf(szNumber, sizeof(szNumber), "%u", (uint32)pJsonStruct->valueint); |
| 384 | } |
| 385 | else |
| 386 | { |
| 387 | #if LLONG_MAX==LLONG_MAX |
| 388 | snprintf(szNumber, sizeof(szNumber), "%lu", pJsonStruct->valueint); |
| 389 | #else |
| 390 | snprintf(szNumber, sizeof(szNumber), "%llu", pJsonStruct->valueint); |
| 391 | #endif |
| 392 | } |
| 393 | } |
nothing calls this directly
no test coverage detected