小编Bob*_*bil的帖子

如何从 nlohmann json 中的字符串获取 JSON 对象?

我有一个字符串,我想将其解析为 json,但_json似乎每次都不起作用。

#include <nlohmann/json.hpp>
#include <iostream>

using nlohmann::json;

int main()
{
    // Works as expected
    json first = "[\"nlohmann\", \"json\"]"_json;
    // Doesn't work
    std::string s = "[\"nlohmann\", \"json\"]"_json;
    json second = s;
}
Run Code Online (Sandbox Code Playgroud)

第一部分有效,第二部分抛出terminate called after throwing an instance of 'nlohmann::detail::type_error' what(): [json.exception.type_error.302] type must be string, but is array

c++ string json nlohmann-json

12
推荐指数
1
解决办法
3万
查看次数

标签 统计

c++ ×1

json ×1

nlohmann-json ×1

string ×1