mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Fixed bug in JsonObjectBase::getBoolFromToken()
This commit is contained in:
		| @@ -10,58 +10,58 @@ using namespace ArduinoJson::Parser; | |||||||
|  |  | ||||||
| int JsonObjectBase::getNestedTokenCount(jsmntok_t* token) | int JsonObjectBase::getNestedTokenCount(jsmntok_t* token) | ||||||
| { | { | ||||||
| 	int end = token->end; |     int end = token->end; | ||||||
| 	int count = 0;	 |     int count = 0;	 | ||||||
|  |  | ||||||
| 	token++; |     token++; | ||||||
|  |  | ||||||
| 	while (token->start < end) |     while (token->start < end) | ||||||
| 	{ |     { | ||||||
| 		token++; |         token++; | ||||||
| 		count++; |         count++; | ||||||
| 	} |     } | ||||||
|  |  | ||||||
| 	return count; |     return count; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool JsonObjectBase::getBoolFromToken(jsmntok_t* token) | bool JsonObjectBase::getBoolFromToken(jsmntok_t* token) | ||||||
| { | { | ||||||
| 	if (token->type != JSMN_PRIMITIVE) return 0; |     if (token == 0 || token->type != JSMN_PRIMITIVE) return 0; | ||||||
|  |  | ||||||
| 	// "true" |     // "true" | ||||||
| 	if (json[token->start] == 't') return true; |     if (json[token->start] == 't') return true; | ||||||
|  |  | ||||||
| 	// "false" |     // "false" | ||||||
| 	if (json[token->start] == 'f') return false; |     if (json[token->start] == 'f') return false; | ||||||
|  |  | ||||||
| 	// "null" |     // "null" | ||||||
| 	if (json[token->start] == 'n') return false; |     if (json[token->start] == 'n') return false; | ||||||
| 	 |      | ||||||
| 	// number |     // number | ||||||
| 	return strtol(json + token->start, 0, 0) != 0; |     return strtol(json + token->start, 0, 0) != 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| double JsonObjectBase::getDoubleFromToken(jsmntok_t* token) | double JsonObjectBase::getDoubleFromToken(jsmntok_t* token) | ||||||
| { | { | ||||||
| 	if (token == 0 || token->type != JSMN_PRIMITIVE) return 0; |     if (token == 0 || token->type != JSMN_PRIMITIVE) return 0; | ||||||
|  |  | ||||||
| 	return strtod(json + token->start, 0); |     return strtod(json + token->start, 0); | ||||||
| } | } | ||||||
|  |  | ||||||
| long JsonObjectBase::getLongFromToken(jsmntok_t* token) | long JsonObjectBase::getLongFromToken(jsmntok_t* token) | ||||||
| { | { | ||||||
| 	if (token == 0 || token->type != JSMN_PRIMITIVE) return 0; |     if (token == 0 || token->type != JSMN_PRIMITIVE) return 0; | ||||||
|  |  | ||||||
| 	return strtol(json + token->start, 0, 0); |     return strtol(json + token->start, 0, 0); | ||||||
| } | } | ||||||
|  |  | ||||||
| char* JsonObjectBase::getStringFromToken(jsmntok_t* token) | char* JsonObjectBase::getStringFromToken(jsmntok_t* token) | ||||||
| { | { | ||||||
| 	if (token == 0 || token->type != JSMN_PRIMITIVE && token->type != JSMN_STRING) |     if (token == 0 || token->type != JSMN_PRIMITIVE && token->type != JSMN_STRING) | ||||||
| 		return 0; |         return 0; | ||||||
|  |  | ||||||
| 	// add null terminator to the string |     // add null terminator to the string | ||||||
| 	json[token->end] = 0; |     json[token->end] = 0; | ||||||
|  |  | ||||||
| 	return json + token->start; |     return json + token->start; | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user