Support return Unicode escapes

This commit is contained in:
2026-03-30 22:50:07 +11:00
parent 120b0e4f01
commit 0c24096c80
4 changed files with 10 additions and 9 deletions

View File

@@ -2379,7 +2379,7 @@ namespace ANSCENTER {
END_TIMER(json_build, "JSON Build Time");
START_TIMER(json_serialize);
std::string result = root.dump();
std::string result = root.dump(-1, ' ', true);
END_TIMER(json_serialize, "JSON Serialize Time");
END_TIMER(json_total, "JSON Conversion Total Time");
@@ -2416,7 +2416,7 @@ namespace ANSCENTER {
root["results"] = detectedObjects;
return root.dump(); // or root.dump(4) for pretty-printed JSON with 4-space indent
return root.dump(-1, ' ', true);
}
// Validation helper methods

View File

@@ -434,7 +434,7 @@ namespace ANSCENTER {
{"kps", KeypointsToString(det.kps)}
});
}
return root.dump();
return root.dump(-1, ' ', true);
}
catch (const std::exception& e) {
this->_logger.LogFatal("ANSALPR::VectorDetectionToJsonString", e.what(), __FILE__, __LINE__);

View File

@@ -197,7 +197,7 @@ namespace ANSCENTER {
{"y", std::to_string(det.box.y)},
{"width", std::to_string(det.box.width)},
{"height", std::to_string(det.box.height)},
{"mask", ""}, // TODO: convert masks to comma separated string
{"mask", ""},
{"extra_info", det.extraInfo},
{"camera_id", det.cameraId},
{"polygon", PolygonToString(det.polygon)},
@@ -205,7 +205,8 @@ namespace ANSCENTER {
});
}
return root.dump();
// ensure_ascii=true escapes non-ASCII chars as \uXXXX for LabVIEW compatibility
return root.dump(-1, ' ', true);
}
catch (const std::exception& e) {
// Add your error logging here if needed
@@ -839,7 +840,7 @@ namespace ANSCENTER {
for (const auto& part : res.parts) {
alprInfo[part.first] = part.second;
}
std::string extraInfoStr = alprInfo.dump();
std::string extraInfoStr = alprInfo.dump(-1, ' ', true);
// Use the same field layout as OCRDetectionToJsonString
jsonResults.push_back({
@@ -858,7 +859,7 @@ namespace ANSCENTER {
{"kps", ""}
});
}
return root.dump();
return root.dump(-1, ' ', true);
} catch (const std::exception&) {
return R"({"results":[],"error":"ALPR serialization failed"})";
}

View File

@@ -1104,10 +1104,10 @@ namespace ANSCENTER {
{"kps", KeypointsToString(det.kps)}
});
}
return root.dump();
// ensure_ascii=true escapes non-ASCII chars as \uXXXX for LabVIEW compatibility
return root.dump(-1, ' ', true);
}
catch (const std::exception& e) {
// Add your error logging here if needed
return R"({"results":[],"error":"Serialization failed"})";
}
}