Пример #1
0
		AnyValue JsonSerializer::toAny(const Json::Value & val)
		{
			std::vector<AnyValue> arr;
			Bundle b;
			switch (val.type())
			{
			case Json::ValueType::arrayValue:
				for (auto e : val) arr.push_back(this->toAny(e));
				return arr;
			case Json::ValueType::booleanValue:
				return val.asBool();
			case Json::ValueType::intValue:
				return (int64_t)val.asInt64();
			case Json::ValueType::nullValue:
				return nullptr;
			case Json::ValueType::objectValue:
				for (Json::ValueConstIterator it = val.begin(); it != val.end(); it++)
				{
					std::string name = it.name();
					b.set(name, this->toAny(*it));
				}
				return b;
			case Json::ValueType::realValue:
				return val.asDouble();
			case Json::ValueType::stringValue:
				return val.asString();
			case Json::ValueType::uintValue:
				return (uint64_t)val.asUInt64();
			}
			return AnyValue();
		}
void mote::http::actions::config::colour_definitions::Set::action(mote::http::Response &response,
	SimpleWeb::Server<SimpleWeb::HTTP>::Request &request)
{
	Json::Value
		json,
		jsonResult;
	Json::Reader reader;
	reader.parse(request.content, json, false);
	for (Json::ValueConstIterator it = json.begin(); it != json.end(); ++it)
	{
		mote::data::ColourDefinition colourDefinition;
		colourDefinition.fromJson(*it);
		this->_colourDefinitions.add(it.name(), colourDefinition);
		jsonResult[it.name()] = true;
	}
	response << jsonResult;
}