我想从扩展中读取json消息:
这是JSON字符串:
"{\"direction\":\"from-page-script\",\"message\":\"{\"command\":\"sign\"}\",\"tab\":1}"
这是我解析它的函数:
UINT getStringValue(string JSON_STRING, string key, string *value)
{
stringstream str(JSON_STRING);
json input = json::parse(JSON_STRING);
//json input;
//str >> input;
*value = "";
if (!input[key].is_null())
*value = input[key].get<string>();
else
return 1;
return 0;
}
解析func:
Unhandled exception at 0x75E308C2 in CkeyAx.exe: Microsoft C++ exception: nlohmann::detail::parse_error at memory location 0x00D6E364. occurred
发布于 2018-06-15 14:15:34
正如注释中所提到的,你在周围添加了不必要的引号{"command":"sign"}
它是一个对象,而不是字符串。格式正确的JSON字符串应该如下所示:
"{\"direction\":\"from-page-script\",\"message\":{\"command\":\"sign\"},\"tab\":1}"
https://stackoverflow.com/questions/-100004941
复制相似问题