|
9 | 9 | ******************************************************************************/
|
10 | 10 |
|
11 | 11 | #include "CJsonObject.hpp"
|
12 |
| -#include <sstream> |
13 | 12 |
|
14 | 13 | #ifdef _WIN32
|
15 | 14 | #define snprintf _snprintf_s
|
@@ -308,9 +307,30 @@ std::string CJsonObject::operator()(const std::string& strKey) const
|
308 | 307 | }
|
309 | 308 | else if (pJsonStruct->type == cJSON_Int)
|
310 | 309 | {
|
311 |
| - std::ostringstream ossNumber; |
312 |
| - ossNumber << pJsonStruct->valueint; |
313 |
| - return(ossNumber.str()); |
| 310 | + char szNumber[128] = {0}; |
| 311 | + if (pJsonStruct->sign == -1) |
| 312 | + { |
| 313 | + if (pJsonStruct->valueint <= (int64)INT_MAX && (int64)pJsonStruct->valueint >= (int64)INT_MIN) |
| 314 | + { |
| 315 | + snprintf(szNumber, sizeof(szNumber), "%d", (int32)pJsonStruct->valueint); |
| 316 | + } |
| 317 | + else |
| 318 | + { |
| 319 | + snprintf(szNumber, sizeof(szNumber), "%ld", (int64)pJsonStruct->valueint); |
| 320 | + } |
| 321 | + } |
| 322 | + else |
| 323 | + { |
| 324 | + if ((uint64)pJsonStruct->valueint <= (uint64)UINT_MAX) |
| 325 | + { |
| 326 | + snprintf(szNumber, sizeof(szNumber), "%u", (uint32)pJsonStruct->valueint); |
| 327 | + } |
| 328 | + else |
| 329 | + { |
| 330 | + snprintf(szNumber, sizeof(szNumber), "%lu", pJsonStruct->valueint); |
| 331 | + } |
| 332 | + } |
| 333 | + return(std::string(szNumber)); |
314 | 334 | }
|
315 | 335 | else if (pJsonStruct->type == cJSON_Double)
|
316 | 336 | {
|
@@ -363,9 +383,30 @@ std::string CJsonObject::operator()(unsigned int uiWhich) const
|
363 | 383 | }
|
364 | 384 | else if (pJsonStruct->type == cJSON_Int)
|
365 | 385 | {
|
366 |
| - std::ostringstream ossNumber; |
367 |
| - ossNumber << pJsonStruct->valueint; |
368 |
| - return(ossNumber.str()); |
| 386 | + char szNumber[128] = {0}; |
| 387 | + if (pJsonStruct->sign == -1) |
| 388 | + { |
| 389 | + if (pJsonStruct->valueint <= (int64)INT_MAX && (int64)pJsonStruct->valueint >= (int64)INT_MIN) |
| 390 | + { |
| 391 | + snprintf(szNumber, sizeof(szNumber), "%d", (int32)pJsonStruct->valueint); |
| 392 | + } |
| 393 | + else |
| 394 | + { |
| 395 | + snprintf(szNumber, sizeof(szNumber), "%ld", (int64)pJsonStruct->valueint); |
| 396 | + } |
| 397 | + } |
| 398 | + else |
| 399 | + { |
| 400 | + if ((uint64)pJsonStruct->valueint <= (uint64)UINT_MAX) |
| 401 | + { |
| 402 | + snprintf(szNumber, sizeof(szNumber), "%u", (uint32)pJsonStruct->valueint); |
| 403 | + } |
| 404 | + else |
| 405 | + { |
| 406 | + snprintf(szNumber, sizeof(szNumber), "%lu", pJsonStruct->valueint); |
| 407 | + } |
| 408 | + } |
| 409 | + return(std::string(szNumber)); |
369 | 410 | }
|
370 | 411 | else if (pJsonStruct->type == cJSON_Double)
|
371 | 412 | {
|
|
0 commit comments