本文整理汇总了C++中json::FastWriter::write方法的典型用法代码示例。如果您正苦于以下问题:C++ FastWriter::write方法的具体用法?C++ FastWriter::write怎么用?C++ FastWriter::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::FastWriter
的用法示例。
在下文中一共展示了FastWriter::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BeginDelete
void AsyncHttpRequest::BeginDelete(std::string path, Json::Value reqData,
std::function<void(std::string)>&& Callback) {
_callback = Callback;
Json::FastWriter writer;
std::string paramstr = writer.write(reqData);
tcp::resolver::query query(_hostname, "http");
std::ostream request_stream(&_request);
request_stream << "DELETE " << path << " HTTP/1.1\r\n";
request_stream << "Host: " << _hostname << "\r\n";
request_stream << "Accept: */*\r\n";
request_stream << "Connection: close\r\n";
request_stream << "Content-Length: " << paramstr.size() << "\r\n\r\n";
request_stream << paramstr;
_resolver.async_resolve(query,
std::bind(&AsyncHttpRequest::handle_resolve,
shared_from_this(), std::placeholders::_1, std::placeholders::_2));
}
示例2: GetSendData
// 获取待发送的数据,可先获取data长度,如:GetSendData(NULL, 0, dataLen);
bool UploadPopLadyAutoInviteTask::GetSendData(void* data, unsigned int dataSize, unsigned int& dataLen)
{
bool result = false;
// 构造json协议
Json::Value root;
root[TARGETID_PARAM] = m_userId;
root[MSGID_PARAM] = m_msg;
root[KEY_PARAM] = atof(m_key.c_str());
Json::FastWriter writer;
string json = writer.write(root);
// 填入buffer
if (json.length() < dataSize) {
memcpy(data, json.c_str(), json.length());
dataLen = json.length();
result = true;
}
return result;
}
示例3: WriteToFile
int WriteToFile()
{
using namespace std;
Json::Value root;
Json::FastWriter writer;
Json::Value person;
person["name"] = "hello world";
person["age"] = 100;
root.append(person);
std::string json_file = writer.write(root);
ofstream ofs;
ofs.open("test1.json");
assert(ofs.is_open());
ofs << json_file;
return 0;
}
示例4: SignalQuality
int SignalQuality(Json::Value& response)
{
if(!g_current_livestream.empty())
{
Json::FastWriter writer;
std::string arguments = writer.write(g_current_livestream);
int retval = ArgusTVJSONRPC("ArgusTV/Control/GetLiveStreamTuningDetails", arguments, response);
//if (retval != E_FAILED)
//{
// printValueTree(response);
//}
return retval;
}
else
{
return E_FAILED;
}
}
示例5: InitParam
// 初始化参数
bool SendCamShareInviteTask::InitParam(const string& userId, CamshareInviteType inviteType, int sessionId, const string& fromName)
{
bool result = false;
if (!userId.empty()) {
m_userId = userId;
Json::Value root;
root[CamshareInviteTypeKey] = inviteType;
root[CamshareInviteTypeSessionIdKey] = sessionId;
root[CamshareInviteTypeFromNameKey] = fromName;
Json::FastWriter writer;
string camShareMsg = writer.write(root);
m_camShareMsg = camShareMsg;
result = true;
}
return result;
}
示例6: write
int SocketIO::write(const Json::Value &data, const string& key){
Json::FastWriter writer;
string msg = writer.write(data);
uint32_t len = htonl(msg.length());
string hmac_key;
hmac_msje(key, msg, hmac_key);
if(send(this->fd, (void*) &len, 4, 0) != 4)
return -1;
if ((uint32_t) send(this->fd,
(void*) msg.c_str(), msg.length(), 0) != msg.length())
return -1;
if ((uint32_t) send(this->fd,
(void*) hmac_key.c_str(), hmac_key.length(), 0) != hmac_key.length())
return -1;
return 0;
}
示例7: queryByISBN
bool CLibrary::queryByISBN(const char * strISBN, IBook ** ppBook)
{
std::string strRequest;
std::string strRespond;
Json::Value value0;
value0["command"] = "library_queryByISBN";
value0["isbn"] = strISBN;
Json::FastWriter writer;
strRequest = writer.write(value0);
if (sendRequest(strRequest, strRespond)) {
Json::Reader reader;
Json::Value value;
reader.parse(strRespond, value);
if (value["result"].asString() == "1") {
TBookBasicInfo *Info = new TBookBasicInfo;
Info->id = value["id"].asInt();
Info->count = value["count"].asInt();
Info->bcount = value["bcount"].asInt();
Info->name = value["name"].asString();
Info->author = value["author"].asString();
Info->isbn = value["isbn"].asString();
Info->publisher = value["publisher"].asString();
CBook *book = new CBook();
book->m_CBBI = Info;
book->id = Info->id;
book->AddRef();
*ppBook = book;
return true;
}
else
{
if (value["result"].asString() == "DatabaseError")
setError(DatabaseError, 0, "database_error");
else setError(InvalidParam, 1, "Invalid strISBN");//jere w about 1
return false;
}
}
else setError(NetworkError, 0, "network_error");
return false;
}
示例8: queryByName
int CLibrary::queryByName(const char * strName, IFvector& vBooks, int nCount, int nTop)
{
std::string strRequest;
std::string strRespond;
Json::Value value0;
value0["command"] = "library_queryByName";
value0["name"] = strName;
value0["nCount"] = nCount;
value0["nTop"] = nTop;
Json::FastWriter writer;
strRequest = writer.write(value0);
if (!sendRequest(strRequest, strRespond))
{
setError(NetworkError, 0, "Network Error");
return -1;
}
Json::Reader reader;
Json::Value value;
reader.parse(strRespond, value);
int num = value[0].asInt();
for (int i = 0; i < num; i++) {
TBookBasicInfo Info;
Json::Value bookinfo = value[i + 1];
Info.id = bookinfo["id"].asInt();
Info.count = bookinfo["count"].asInt();
Info.bcount = bookinfo["bcount"].asInt();
Info.name = bookinfo["name"].asString();
Info.author = bookinfo["author"].asString();
Info.isbn = bookinfo["isbn"].asString();
Info.publisher = bookinfo["publisher"].asString();;
CBook *book = new CBook;
TBookBasicInfo *pInfo = new TBookBasicInfo(Info);
book->m_CBBI = pInfo;
book->id = Info.id;
//book->setBasicInfo(Info);
vBooks.push_back(book);
}
return num;
}
示例9: Pkt
void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
{
cServer * Server = cRoot::Get()->GetServer();
AString ServerDescription = Server->GetDescription();
auto NumPlayers = static_cast<signed>(Server->GetNumPlayers());
auto MaxPlayers = static_cast<signed>(Server->GetMaxPlayers());
AString Favicon = Server->GetFaviconData();
cRoot::Get()->GetPluginManager()->CallHookServerPing(*m_Client, ServerDescription, NumPlayers, MaxPlayers, Favicon);
// Version:
Json::Value Version;
Version["name"] = "Cuberite 1.11";
Version["protocol"] = cProtocolRecognizer::PROTO_VERSION_1_11_0;
// Players:
Json::Value Players;
Players["online"] = NumPlayers;
Players["max"] = MaxPlayers;
// TODO: Add "sample"
// Description:
Json::Value Description;
Description["text"] = ServerDescription.c_str();
// Create the response:
Json::Value ResponseValue;
ResponseValue["version"] = Version;
ResponseValue["players"] = Players;
ResponseValue["description"] = Description;
m_Client->ForgeAugmentServerListPing(ResponseValue);
if (!Favicon.empty())
{
ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
}
// Serialize the response into a packet:
Json::FastWriter Writer;
cPacketizer Pkt(*this, 0x00); // Response packet
Pkt.WriteString(Writer.write(ResponseValue));
}
示例10: SendData
IOTAPI::IOTAPI_err IOT_API::SendData(const std::string& devId, const std::vector<IOT_WriteData>& data) const
{
IOTAPI::IOTAPI_err ret = IOT_ERR_PARAM;
Json::Value writeData;
if(data.empty()) {
return ret;
}
for(uint32_t i = 0; i < data.size(); ++i)
{
Json::Value oneData;
if(data.at(i).ToJSON(oneData)) {
writeData.append(oneData);
} else {
return ret;
}
}
std::string url = m_servAddr + IOT_WRITE_PATH + "/" + devId;
std::string response;
Json::FastWriter fastWriter;
std::string json = fastWriter.write(writeData);
ret = m_client.PostAndReadResponse(url, m_authName, m_password, json, response);
Json::Value writeAnswer;
if(ParseJson(response, writeAnswer)) {
if(ret != IOTAPI::IOT_ERR_OK) {
ret = GetErrorCode(writeAnswer);
} else if(writeAnswer.isMember("totalWritten") && writeAnswer["totalWritten"].isIntegral()) {
if(writeAnswer["totalWritten"].asUInt() == data.size())
ret = IOT_ERR_OK;
} else {
ret = IOT_ERR_GENERAL;
}
}
return ret;
}
示例11: PerformAction
bool ContextMenuUtil::PerformAction(int command)
{
ContextMenuItem* contextMenuItem;
if (!GetContextMenuItem(command, &contextMenuItem))
{
return false;
}
Json::Value jsonValue;
jsonValue[NATIVITY_UUID] = StringUtil::toString(contextMenuItem->GetUuid()->c_str());
for (vector<wstring>::iterator it = _selectedFiles->begin(); it != _selectedFiles->end(); it++)
{
wstring selectedFile = *it;
jsonValue[NATIVITY_FILES].append(StringUtil::toString(selectedFile));
}
Json::Value jsonRoot;
jsonRoot[NATIVITY_COMMAND] = NATIVITY_CONTEXT_MENU_ACTION;
jsonRoot[NATIVITY_VALUE] = jsonValue;
Json::FastWriter jsonWriter;
wstring* jsonMessage = new wstring();
jsonMessage->append(StringUtil::toWstring(jsonWriter.write(jsonRoot)));
wstring* response = new wstring();
if (!_communicationSocket->SendMessageReceiveResponse(jsonMessage->c_str(), response))
{
return false;
}
return true;
}
示例12: sdgetsize
std::string ScreenDisplayNDK::sdgetsize() {
bb::device::DisplayInfo display;
Json::FastWriter writer;
Json::Value root;
double physx = display.physicalSize().width();
double physy = display.physicalSize().height();
int pixx = display.pixelSize().width();
int pixy = display.pixelSize().height();
double ppmm = 0;
double ppmmx = 0;
double ppmmy = 0;
double pshape = 0;
double physdiag = 0; // Diagonal metrics
double pixdiag = 0;
if((pixx > 0) && (pixy > 0) && (physx > 0) && (physy > 0)) {
ppmmx = pixx / physx;
ppmmy = pixy / physy;
pshape = (ppmmx / ppmmy);
physdiag = sqrt((physx * physx) + (physy * physy));
pixdiag = sqrt((pixx * pixx) + (pixy * pixy));
ppmm = pixdiag / physdiag;
}
root["physicalWidth"] = physx;
root["physicalHeight"] = physy;
root["pixelWidth"] = pixx;
root["pixelHeight"] = pixy;
root["ppmm"] = ppmm;
root["ppmmX"] = ppmmx;
root["ppmmY"] = ppmmy;
root["ppi"] = ppmm * MMPERINCH;
root["ppiX"] = ppmmx * MMPERINCH;
root["ppiY"] = ppmmy * MMPERINCH;
root["pixelShape"] = pshape;
return writer.write(root);
}
示例13: HandlePacketStatusRequest
void cProtocolRecognizer::HandlePacketStatusRequest(void)
{
cServer * Server = cRoot::Get()->GetServer();
AString ServerDescription = Server->GetDescription();
auto NumPlayers = static_cast<signed>(Server->GetNumPlayers());
auto MaxPlayers = static_cast<signed>(Server->GetMaxPlayers());
AString Favicon = Server->GetFaviconData();
cRoot::Get()->GetPluginManager()->CallHookServerPing(*m_Client, ServerDescription, NumPlayers, MaxPlayers, Favicon);
// Version:
Json::Value Version;
Version["name"] = "Cuberite " MCS_CLIENT_VERSIONS;
Version["protocol"] = MCS_LATEST_PROTOCOL_VERSION;
// Players:
Json::Value Players;
Players["online"] = NumPlayers;
Players["max"] = MaxPlayers;
// TODO: Add "sample"
// Description:
Json::Value Description;
Description["text"] = ServerDescription.c_str();
// Create the response:
Json::Value ResponseValue;
ResponseValue["version"] = Version;
ResponseValue["players"] = Players;
ResponseValue["description"] = Description;
if (!Favicon.empty())
{
ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
}
Json::FastWriter Writer;
AString Response = Writer.write(ResponseValue);
cPacketizer Pkt(*this, 0x00); // Response packet
Pkt.WriteString(Response);
}
示例14: comm_type
std::string const* MessageFactory::CreateMoveMessage(enum Tetromino::Move move, int pieceId) const {
Json::Value root;
Json::FastWriter writer;
Json::Value comm_type ("GameMove");
Json::Value client_token (m_clientToken);
root["comm_type"] = comm_type;
root["client_token"] = client_token;
if (move == Tetromino::left) {
Json::Value moveV ("left");
root["move"] = moveV;
}
else if (move == Tetromino::right) {
Json::Value moveV ("right");
root["move"] = moveV;
}
else if (move == Tetromino::down) {
Json::Value moveV ("down");
root["move"] = moveV;
}
else if (move == Tetromino::lrotate) {
Json::Value moveV ("lrotate");
root["move"] = moveV;
}
else if (move == Tetromino::rrotate) {
Json::Value moveV ("rrotate");
root["move"] = moveV;
}
else if (move == Tetromino::drop) {
Json::Value moveV ("drop");
root["move"] = moveV;
}
Json::Value number (pieceId);
root["piece_number"] = number;
std::string const* serialized = new std::string(writer.write(root));
return serialized;
}
示例15: to_json
// register obj
std::string CmdRegister::to_json()
{
std::string jstr;
Json::Features::all();
Json::Value root;
// Json::StyledWriter jwriter;
Json::FastWriter fjwriter;
root["cmd_id"] = cmd_id;
root["cmd_seq"] = cmd_seq;
root["display_name"] = display_name;
root["user_name"] = user_name;
root["password"] = password;
root["sip_server"] = sip_server;
root["acc_id"] = acc_id;
root["unregister"] = unregister;
jstr = fjwriter.write(root);
return jstr;
}