我有一个 REST API,它返回一个带有文件元数据的字符串。在这些文件中,我有一个名称中有 "" (0xEF0xBF0xBF, link ) 字符。当我尝试解析这样的响应时,我收到异常消息:
e = {_message="* Line 1, Column 13 Syntax error: Malformed string literal" }
这是我要解析的字符串:
{"files":[["Thunderbolt Gigabit Ethernet Adapter.txt",["bc288518-c426-4dbd-9600-a213a35d1c04",1447772221866,9,"Bartosz","Siewior"]],["System.Windows.Interactivity .dll",["56ce759b-019b-4723-8fca-7af877908971",1440507238241,55904,"Bartosz","Siewior"]]],"folderPermission":[["MODIFY"]],"directories":[] }
我用来接收和解析字符串的代码:
// ...
client.request(request).then([&](web::http::http_response response) {
status_code = response.status_code();
//response.extract_json(true).then([&](pplx::task<web::json::value> previousTask) {
response.extract_string().then([&](pplx::task<utility::string_t> previousTask) {
try {
utility::string_t str_response = previousTask.get();
web::json::value root;
root = web::json::value::parse(str_response);
}
catch (const web::http::http_exception& e) {
std::wstringstream ss;
ss << e.what();
str_response = ss.str();
}
catch (const web::json::json_exception& e) {
std::wstringstream ss;
ss << e.what();
str_response = ss.str();
}
TaskExecutionData data = { task.id, status_code, str_response.c_str() };
callback(data);
}).wait();
}).wait();
VS2013 JSON Visualizer 可以正确解析并显示结果:VS_json_visualizer
我已经尝试过 C++REST 2.5.0 和 2.6.0 版本,它们都无法解析该字符串......你有什么想法吗?