に私のために働いている鉱山は、Windows用のように見える方法:
#include "stdafx.h"
#include "json\json.h"
int _tmain(int argc, _TCHAR* argv[])
{
//save in a file so we know it was called
FILE *fh_debug; int errorcode;
errorcode =fopen_s(&fh_debug, "debug.txt","ab+");
std::string msg = "Host Called";
fwrite(msg.c_str(), sizeof(char),msg.size(),fh_debug);
unsigned int uiSize = 0;
std::string inputStr;
//read the first four bytes (=> Length)
for (int i = 0; i < 4; i++)
{
int read_char = getchar();
uiSize += read_char * (int) pow(2.0, i * 8);
}
//for debug "0000" = 808464432
if (uiSize == 808464432) {
uiSize = 0; inputStr = "{\"text\":\"tester\"}";
}
//debug record size
msg = std::to_string(uiSize);
fwrite(msg.c_str(), sizeof(char),msg.size(),fh_debug);
//read the text
for (unsigned int i = 0; i < uiSize; i++)
{
inputStr += getchar();
}
//debug record json message
msg = inputStr;
fwrite(msg.c_str(), sizeof(char),msg.size(),fh_debug);
//get the text
std::string theText;
Json::Value jsonRoot;
Json::Reader jsonReader;
bool OK = jsonReader.parse(inputStr, jsonRoot);
try {
theText = jsonRoot.get("text", "no text element").asString();
}
catch (std::exception& e)
{
std::cout << e.what() << '\n';
throw e;
}
//debug record json message
msg = theText;
fwrite(msg.c_str(), sizeof(char),msg.size(),fh_debug);
std::string strOut = "{\"text\":\"Hello " + theText + "\"}";
uiSize = strOut.length();
msg = strOut;
fwrite(msg.c_str(), sizeof(char),msg.size(),fh_debug);
std::cout << char(((uiSize>>0) & 0xFF));
std::cout << char(((uiSize>>8) & 0xFF));
std::cout << char(((uiSize>>16) & 0xFF));
std::cout << char(((uiSize>>24) & 0xFF));
std::cout << strOut.c_str();
return 0;
}
は質問が明確ではないですか? – user3856170
質問を編集して質問を理解しやすくしました。あなたの意図する質問が届かない場合は、私に知らせて、それを自由に変更してください。 – Sometowngeek
質問が投票されたのはなぜですか? – user3856170