Beispiel #1
0
void DirectHandler::handleData(const JSONEntity& val)
{
	if (isArray())
	{
		switch(val.type())
		{
		case JSONEntity::JSON_T_STRING:
			_data.push_back(val.toString());
			break;
		case JSONEntity::JSON_T_INTEGER:
			_data.push_back(val.toInteger());
			break;
		case JSONEntity::JSON_T_FLOAT:
			_data.push_back(val.toFloat());
			break;
		case JSONEntity::JSON_T_TRUE:
			_data.push_back(true);
			break;
		case JSONEntity::JSON_T_FALSE:
			_data.push_back(false);
			break;
		case JSONEntity::JSON_T_NULL:
			_data.push_back(Var());
			break;
		default:
			throw Poco::InvalidArgumentException("Unknown type.");
		}
	}
}
Beispiel #2
0
 void handleString(const JSONEntity& val)
 {
     if (_key.toString() == "firstName")
         stream() << val.toString();
     else if (_key.toString() == "lastName")
         stream() << ' ' << val.toString();
     else if (_key.toString() == "streetAddress")
         stream() << " lives at " << val.toString();
     else if (_key.toString() == "city")
         stream() << " in " << val.toString();
     else if (_key.toString() == "state")
         stream() << ", " << val.toString();
 }
Beispiel #3
0
void DirectHandler::handleValue(const JSONEntity& val)
{
	if (0 == icompare(_key, "action"))
	{
		handleAction(val.toString());
	}
	else if (0 == icompare(_key, "method"))
	{
		handleMethod(val.toString());
	}
	else if (0 == icompare(_key, "data"))
	{
		handleData(val);
	}
	else if (0 == icompare(_key, "type"))
	{
		handleType(val.toString());
	}
	else if (0 == icompare(_key, "tid"))
	{
		handleTID(val.toInteger());
	}
}
Beispiel #4
0
 void handleInteger(const JSONEntity& val)
 {
     if (_key.toString() == "postalCode")
         stream() << ' '  << val.toInteger() << '.' << std::endl;
 }
Beispiel #5
0
void JSONHandler::handle(const JSONEntity& value)
{
	switch(value.type())
	{
	case JSONEntity::JSON_T_ARRAY_BEGIN:    
		handleArrayBegin();
		setKey(false);
		incrementLevel();
		break;

	case JSONEntity::JSON_T_ARRAY_END:
		poco_assert(!isKey());
		if (level() > 0)
			decrementLevel();
		handleArrayEnd();
		break;

	case JSONEntity::JSON_T_OBJECT_BEGIN:
		handleObjectBegin();
		setKey(false);
		incrementLevel();
		break;

	case JSONEntity::JSON_T_OBJECT_END:
		poco_assert(!isKey());
		if (level() > 0)
			decrementLevel();
		handleObjectEnd();
		break;

	case JSONEntity::JSON_T_VALUE_SEPARATOR:
		handleValueSeparator();
		setKey(false);
		break;

	case JSONEntity::JSON_T_INTEGER:
		handleInteger(value);
		setKey(false);
		break;

	case JSONEntity::JSON_T_FLOAT:
		handleFloat(value);
		setKey(false);
		break;

	case JSONEntity::JSON_T_NULL:
		handleNull();
		setKey(false);
		break;

	case JSONEntity::JSON_T_TRUE:
		handleTrue();
		setKey(false);
		break;

	case JSONEntity::JSON_T_FALSE:
		handleFalse();
		setKey(false);
		break;

	case JSONEntity::JSON_T_KEY:
		setKey(true);
		handleKey(value);
		break;   

	case JSONEntity::JSON_T_STRING:
		handleString(value);
		setKey(false);
		break;

	default:
		poco_assert (false);
		break;
	}
}