예제 #1
0
void Pet::fromJson(nlohmann::json& val)
{
    if(val.find("id") != val.end())
    {
        setId(val.at("id"));
    }
    if(val.find("category") != val.end())
    {
        if(!val["category"].is_null())
        {
            Category newItem(Category());
            newItem.fromJson(val["category"]);
            setCategory( newItem );
        }
        
    }
    setName(val.at("name"));
    {
        m_PhotoUrls.clear();
        nlohmann::json jsonArray;
                for( auto& item : val["photoUrls"] )
        {
            m_PhotoUrls.push_back(item);
            
        }
    }
    {
        m_Tags.clear();
        nlohmann::json jsonArray;
        if(val.find("tags") != val.end())
        {
        for( auto& item : val["tags"] )
        {
            
            if(item.is_null())
            {
                m_Tags.push_back( Tag(nullptr) );
            }
            else
            {
                Tag newItem(Tag());
                newItem.fromJson(item);
                m_Tags.push_back( newItem );
            }
            
        }
        }
    }
    if(val.find("status") != val.end())
    {
        setStatus(val.at("status"));
        
    }
    
}
예제 #2
0
void ExprFunction<T>::set(const nlohmann::json &j, const Tvarvec &vars) {
    Tconstvec consts;
    auto it = j.find("constants");
    if (it != j.end())
        for (auto i = it->begin(); i != it->end(); ++i)
            consts.push_back({i.key(), i.value()});
    set(j.at("function"), vars, consts);
}
files_and_template_pages_parameters::files_and_template_pages_parameters(const nlohmann::json &config)
{
	// Optional parameters
	try {
		const auto &default_behavior =
			config.at("default_behavior").get<std::string>();
		
		if (default_behavior == "files") {
			this->default_behavior =
				files_and_template_pages_parameters::behavior::files;
		} else if (default_behavior == "template_pages") {
			this->default_behavior =
				files_and_template_pages_parameters::behavior::template_pages;
		} else {
			throw std::logic_error("Incorrect config");
		}
	} catch (const std::out_of_range &) {}
	
	
	try {
		this->change_behavior_regex =
			config.at("change_behavior_regex").get<std::string>();
	} catch (const std::out_of_range &) {}
}
예제 #4
0
void User::fromJson(nlohmann::json& val)
{
    if(val.find("id") != val.end())
    {
        setId(val.at("id"));
    }
    if(val.find("username") != val.end())
    {
        setUsername(val.at("username"));
        
    }
    if(val.find("firstName") != val.end())
    {
        setFirstName(val.at("firstName"));
        
    }
    if(val.find("lastName") != val.end())
    {
        setLastName(val.at("lastName"));
        
    }
    if(val.find("email") != val.end())
    {
        setEmail(val.at("email"));
        
    }
    if(val.find("password") != val.end())
    {
        setPassword(val.at("password"));
        
    }
    if(val.find("phone") != val.end())
    {
        setPhone(val.at("phone"));
        
    }
    if(val.find("userStatus") != val.end())
    {
        setUserStatus(val.at("userStatus"));
    }
    
}
예제 #5
0
void CGC6500::HandleMessage( const nlohmann::json &commandIn )
{
	try
	{		
		if( commandIn[ "cmd" ].get<std::string>() == "chCmd" )
		{
			size_t channelNum = commandIn.at( "ch" ).get<size_t>();
			
			// Pass message down to specified channel
			m_pChannels.at( channelNum )->HandleMessage( commandIn );
		}
		else
		{
			throw std::runtime_error( "Unknown command" );
		}
	}
	catch( const std::exception &e )
	{
		std::cerr << "Error handling message: " << e.what() << std::endl;
	}
}