예제 #1
0
void StatementItem::fromJson(const Json::Value& json) {
    if (json.isMember("refId")) {
        refId = json["refId"].asString();
    }
    if (json.isMember("itemDate")) {
        strptime(json["itemDate"].asString().c_str(), "%Y-%m-%dT%H:%M:%S.000Z", &itemDate);
    }
    if (json.isMember("amount")) {
        amount = json["amount"].asDouble();
    }
    if (json.isMember("balance")) {
        balance = json["balance"].asDouble();
    }
    if (json.isMember("itemClass")) {
        itemClass = json["itemClass"].asString();
    }
    if (json.isMember("itemClassData")) {
        for (Json::ValueConstIterator itr = json["itemClassData"].begin(); itr != json["itemClassData"].end(); ++itr) {
            std::string value;
            value = (*itr).asString();
            itemClassData[itr.key().asString()] = value;
        }
    }
    if (json.isMember("legacyData")) {
        legacyData.fromJson(json["legacyData"]);
    }
}
예제 #2
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::Remove::action(mote::http::Response &response,
	SimpleWeb::Server<SimpleWeb::HTTP>::Request &request)
{
	Json::Value
		json,
		jsonResult;
	Json::Reader reader;
	reader.parse(request.content, json);
	Json::Value &jsonColours = json["colours"];
	for (Json::ValueConstIterator it = jsonColours.begin(); it != jsonColours.end(); ++it)
	{
		this->_colourDefinitions.remove(it->asString());
		jsonResult[it->asString()] = true;
	}
	response << jsonResult;
}
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;
}
예제 #5
0
bool Message::ToJson(Json::Value& root) const {
    BOOST_ASSERT(root.isObject());
    if (!root.isObject()) {
        return false;
    }

    root["type"] = type_;

    if (!params_.empty()) {
        Json::Value params(Json::objectValue);
        Json::ValueConstIterator itr = params_.begin();
        Json::ValueConstIterator end = params_.end();
        for (; itr != end; ++itr) {
            params[itr.key().asString()] = *itr;
        }
        root["params"] = params;
    }

    return true;
}
예제 #6
0
bool Request::ToJson(std::string& json) const {

    Json::Value root(Json::objectValue);
    if (!Message::ToJson(root)) {
        return false;
    }

    root["id"] = msg_id_;
    root["query"] = query_;

    if (!header_.empty()) {
        Json::Value header(Json::objectValue);
        Json::ValueConstIterator itr = header_.begin();
        Json::ValueConstIterator end = header_.end();
        for (; itr != end; ++itr) {
            header[itr.key().asString()] = *itr;
        }
        root["header"] = header;
    }
    
    return ::WriteJson(root, json, false);
}