本文整理汇总了C++中JsonObject::measureLength方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonObject::measureLength方法的具体用法?C++ JsonObject::measureLength怎么用?C++ JsonObject::measureLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject::measureLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: putJson
bool WebServiceFSM::putJson(JsonObject& msg) {
// .printTo stupidly writes a '\0' in its last position, so any destination
// printed to must ask for one more than the strlen of the JSON. At the
// other end of the connection, Node.js will choke on PUT data if you throw a
// null byte at it. So, the FILE* must be as large as the JSON string, not
// counting the null byte.
// I place the primary blame on ArduinoJson for this one. Honte, Benoit!
char to_server[MAX_MSG_SIZE];
msg.printTo(to_server, 1+msg.measureLength());
auto fout = fmemopen(to_server, msg.measureLength(), "r");
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
curl_easy_setopt(curl, CURLOPT_READDATA, fout);
char from_server[MAX_MSG_SIZE];
auto fin = fmemopen(from_server, MAX_MSG_SIZE, "w");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fin);
res = curl_easy_perform(curl);
fclose(fin);
fclose(fout);
// Turn off PUT mode
curl_easy_setopt(curl, CURLOPT_UPLOAD, 0);
// Check for errors
if(res != CURLE_OK) {
fprintf(stderr, "WebQ: Failed to access %s: %s\n", "localhost",
curl_easy_strerror(res));
}
else {
fprintf(stderr, "WebQ: Connection successful, received '%s'\n", from_server);
}
return res == CURLE_OK;
}
示例2: postJson
bool WebServiceFSM::postJson(JsonObject& msg) {
// .printTo stupidly writes a '\0' in its last position, so any destination
// printed to must ask for one more than the strlen of the JSON.
char to_server[MAX_MSG_SIZE];
msg.printTo(to_server, 1+msg.measureLength());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, to_server);
char from_server[MAX_MSG_SIZE];
auto fin = fmemopen(from_server, MAX_MSG_SIZE, "w");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fin);
res = curl_easy_perform(curl);
fclose(fin);
// Check for errors
if(res != CURLE_OK) {
fprintf(stderr, "WebQ: Failed to access %s: %s\n", "localhost",
curl_easy_strerror(res));
}
else {
fprintf(stderr, "WebQ: Connection successful, received '%s'\n", from_server);
}
return res == CURLE_OK;
}
示例3: sendTriggerEventWithData
String IFTTTMaker::sendTriggerEventWithData(String eventName, JsonObject& payload) {
String response="";
bool finishedHeaders = false;
bool currentLineIsBlank = true;
long now;
bool avail;
// Connect with IFTTT
if (client->connect(HOST, SSL_PORT)) {
//Serial.println(".... connected to server");
String a="";
char c;
int ch_count=0;
client->print("POST /trigger/"+eventName+"/with/key/"+_key);
client->println(" HTTP/1.1");
// Host header
client->print("Host:"); client->println(HOST);
// JSON content type
client->println("Content-Type: application/json");
// Content length
int length = payload.measureLength();
client->print("Content-Length:"); client->println(length);
// End of headers
client->println();
// POST message body
String out;
payload.printTo(out);
//Serial.println(out);
client->println(out);
now=millis();
avail=false;
//Serial.println("starting timer");
while (millis()-now<1500) {
while (client->available()) {
char c = client->read();
//Serial.print(c);
response = response + c;
}
}
}
//Serial.println("response");
//Serial.println(response);
return response;
}