Boost C++ 库

...世界上最受推崇、设计最精良的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ Coding Standards

serialize - Boost C++ 函数库

serialize

返回一个表示序列化元素的字符串。

提要

定义在头文件 <boost/json/serialize.hpp> 中。

std::string
serialize(
    value const& t,
    serialize_options const& opts = {}); (1)

std::string
serialize(
    array const& t,
    serialize_options const& opts = {}); (2)

std::string
serialize(
    object const& t,
    serialize_options const& opts = {}); (3)

std::string
serialize(
    string const& t,
    serialize_options const& opts = {}); (4)

template<
    class T>
std::string
serialize(
    T const& t,
    serialize_options const& opts = {}); (5)

std::string
serialize(
    string_view t,
    serialize_options const& opts = {}); (6)

描述

此函数将 t 序列化为 JSON,并将其作为 std::string 返回。

复杂度

t 的大小成线性关系。

异常安全性

强保证。分配调用可能会抛出异常。

返回值

序列化后的字符串。

参数

名称 描述

t

要序列化的值

opts

序列化器的选项。如果省略此参数,则序列化器将仅输出标准 JSON。

便捷头文件 <boost/json.hpp>