我有一个字符串,我想将其解析为 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
。