Пример #1
0
void xml2json_to_array_form(const char *name, rapidjson::Value &jsvalue, rapidjson::Value &jsvalue_chd, rapidjson::Document::AllocatorType& allocator)
{
    rapidjson::Value jsvalue_target; // target to do some operation
    rapidjson::Value jn;             // this is a must, partially because of the latest version of rapidjson
    jn.SetString(name, allocator);
    jsvalue_target = jsvalue.FindMember(name)->value;
    if(jsvalue_target.IsArray())
    {
        jsvalue_target.PushBack(jsvalue_chd, allocator);
        jsvalue.RemoveMember(name);
        jsvalue.AddMember(jn, jsvalue_target, allocator);
    }
    else
    {
        rapidjson::Value jsvalue_array;
        //jsvalue_array = jsvalue_target;
        jsvalue_array.SetArray();
        jsvalue_array.PushBack(jsvalue_target, allocator);
        jsvalue_array.PushBack(jsvalue_chd, allocator);
        jsvalue.RemoveMember(name);
        jsvalue.AddMember(jn, jsvalue_array, allocator);
    }
}
Пример #2
0
bool Account::load_config(rapidjson::Value& obj)
{
    if (!obj.IsObject()) {
        return false;
    }
    m_properties["Name"] = m_name;
    m_protocol = Protocol::from_object(obj["Protocol"], obj["Config"]);
    obj.RemoveMember("Config");
    if (obj.HasMember("Interval") && obj["Interval"].IsUint()) {
        unsigned interval = obj["Interval"].GetUint();
        if (interval > 0) {
            m_interval = interval;
        }
    }
    for (auto it = obj.MemberBegin(); it != obj.MemberEnd(); ++it) {
        if (Application::read_event(m_notifications, it)) {
            it->value.SetNull();
        }
    }
    Application::generate_properties("", m_properties, obj);
    return m_protocol != nullptr;
}