Added toJson function for single result

This commit is contained in:
Matt Hill
2016-10-23 10:48:57 -04:00
parent 469c4fd6d7
commit a8c3f90f9f
4 changed files with 22 additions and 0 deletions

View File

@@ -82,6 +82,10 @@ namespace alpr
{
return AlprImpl::toJson(results);
}
std::string Alpr::toJson( AlprPlateResult result )
{
return AlprImpl::toJson(result);
}
AlprResults Alpr::fromJson(std::string json) {
return AlprImpl::fromJson(json);

View File

@@ -163,6 +163,7 @@ namespace alpr
static std::string toJson(const AlprResults results);
static std::string toJson(const AlprPlateResult result);
static AlprResults fromJson(std::string json);
bool isLoaded();

View File

@@ -542,6 +542,21 @@ namespace alpr
std::string AlprImpl::toJson( const AlprPlateResult result )
{
cJSON *resultObj = createJsonObj( &result );
char *out;
out=cJSON_PrintUnformatted(resultObj);
cJSON_Delete(resultObj);
string response(out);
free(out);
return response;
}
cJSON* AlprImpl::createJsonObj(const AlprPlateResult* result)
{
cJSON *root, *coords, *candidates;

View File

@@ -99,6 +99,8 @@ namespace alpr
void setDefaultRegion(std::string region);
static std::string toJson( const AlprResults results );
static std::string toJson( const AlprPlateResult result );
static AlprResults fromJson(std::string json);
static std::string getVersion();