JSON 使用 cpprestsdk 序列化 std::list 和 std::map



我正在使用cpprestsdk在C++中编写一个使用REST服务的服务器应用程序。在我的应用程序中,我必须将包含 std::list 和 std::map 对象的类序列化为 JSON。

有没有使用 cpprestsdk(https://github.com/Microsoft/cpprestsdk/( 序列化 STL 类的示例

您可以将std::liststd::map序列化为 JSON 数组。std::map的一个例子是

void mapToJson()
{
    web::json::value result = web::json::value::array();
    std::map<int, utility::string_t> m;
    int i = 0;
    for each (std::pair<int, utility::string_t> p in m)
    {
        web::json::value obj = web::json::value::object();
        obj[U("integer")] = web::json::value(p.first);
        obj[U("string")] = web::json::value(p.second);
        result[i++] = obj;
    }
}

最新更新