Skip to content
This repository was archived by the owner on Mar 21, 2023. It is now read-only.

Commit fb29227

Browse files
authored
Merge pull request #61 from open-amt-cloud-toolkit/feat_message_formatting
feat: format json status messages
2 parents db924a9 + 26629a1 commit fb29227

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

main.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <thread>
88
#include <cpprest/ws_client.h>
99
#include <cpprest/json.h>
10+
#include <algorithm>
1011
#include "port.h"
1112
#include "lms.h"
1213
#include "commands.h"
@@ -271,7 +272,22 @@ int main(int argc, char* argv[])
271272
g_timeout_val = 0;
272273

273274
// exit
274-
std::cout << std::endl << msgMessage << std::endl;
275+
try {
276+
std::cout << std::endl;
277+
utility::string_t tmp = utility::conversions::convertstring(msgMessage);
278+
web::json::value parsed = web::json::value::parse(tmp);
279+
for (const auto& obj : parsed.as_object()) {
280+
std::string key = utility::conversions::to_utf8string(obj.first);
281+
std::string value = utility::conversions::to_utf8string(obj.second.serialize());
282+
value.erase(std::remove(value.begin(), value.end(), '"'), value.end());
283+
std::cout << key << ": " << value << std::endl;
284+
}
285+
}
286+
catch (...)
287+
{
288+
std::cout << std::endl << msgMessage << std::endl;
289+
}
290+
275291
return;
276292
}
277293
else if (msgStatus.compare("failed")==0)
@@ -280,7 +296,22 @@ int main(int argc, char* argv[])
280296
g_timeout_val = 0;
281297

282298
// exit
283-
std::cout << std::endl << msgMessage << std::endl;
299+
try {
300+
std::cout << std::endl;
301+
utility::string_t tmp = utility::conversions::convertstring(msgMessage);
302+
web::json::value parsed = web::json::value::parse(tmp);
303+
for (const auto& obj : parsed.as_object()) {
304+
std::string key = utility::conversions::to_utf8string(obj.first);
305+
std::string value = utility::conversions::to_utf8string(obj.second.serialize());
306+
value.erase(std::remove(value.begin(), value.end(), '"'), value.end());
307+
std::cout << key << ": " << value << std::endl;
308+
}
309+
}
310+
catch (...)
311+
{
312+
std::cout << std::endl << msgMessage << std::endl;
313+
}
314+
284315
return;
285316
}
286317

0 commit comments

Comments
 (0)