/*
* Returns the token for the value associated with the specified key
*/
jsmntok_t* JsonHashTable::getToken(const char* desiredKey)
{	
	// sanity check
	if (json == 0 || tokens == 0 || desiredKey == 0)
		return 0;

	// skip first token, it's the whole object
	jsmntok_t* currentToken = tokens + 1;

	// scan each keys
	for (int i = 0; i < tokens[0].size / 2 ; i++)
	{
		// get key token string
		char* key = getStringFromToken(currentToken);

		// compare with desired name
		if (strcmp(desiredKey, key) == 0)
		{
			// return the value token that follows the key token
			return currentToken + 1;
		}

		// move forward: key + value + nested tokens
		currentToken += 2 + getNestedTokenCount(currentToken + 1);
	}

	// nothing found, return NULL
	return 0; 
}
char* JsonHashTable::getString(const char* key)
{
	return getStringFromToken(getToken(key));
}
Ejemplo n.º 3
0
char* JsonArray::getString(int index)
{
    return getStringFromToken(getToken(index));
}