Skip to content
Mvb1122 edited this page Sep 3, 2021 · 4 revisions

Examples / Open-source code using PicoJSON

How to de/seralize a std::deque?

template<typename T>
picojson::value toJson(const std::deque<T>& items)
{
    picojson::array arr;

    for(const auto& i: items)
    {
        arr.push_back(picojson::value>(i));
    }

    return picojson::value(arr);
}

template<typename T>
std::deque<T>& fromJson(std::deque<T>& items, const picojson::value& input)
{
    if(input.is<picojson::array>())
    {
        const auto& array = input.get<picojson::array>();
        for(const auto a: array)
        {
            items.push_back(a.get<T>());
        }
    }

    return items;
}
Clone this wiki locally