本文整理汇总了C++中DynamicJsonBuffer::createObject方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicJsonBuffer::createObject方法的具体用法?C++ DynamicJsonBuffer::createObject怎么用?C++ DynamicJsonBuffer::createObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicJsonBuffer
的用法示例。
在下文中一共展示了DynamicJsonBuffer::createObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveConfig
void saveConfig(MeteoConfig& cfg)
{
ActiveConfig = cfg;
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
JsonObject& network = jsonBuffer.createObject();
root["network"] = network;
network["ssid"] = cfg.NetworkSSID.c_str();
network["password"] = cfg.NetworkPassword.c_str();
JsonObject& correction = jsonBuffer.createObject();
root["correction"] = correction;
correction["T1"] = cfg.AddT1;
correction["T2"] = cfg.AddT2;
correction["TZ"] = cfg.AddTZ;
JsonObject& trigger = jsonBuffer.createObject();
root["trigger"] = trigger;
trigger["type"] = (int)cfg.Trigger;
trigger["min"] = cfg.RangeMin;
trigger["max"] = cfg.RangeMax;
char buf[3048];
root.prettyPrintTo(buf, sizeof(buf));
fileSetContent(METEO_CONFIG_FILE, buf);
}
示例2: _onDeviceInfoRequest
void BootConfig::_onDeviceInfoRequest() {
Logger.logln("Received device info request");
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
json["device_id"] = Helpers.getDeviceId();
json["homie_version"] = VERSION;
JsonObject& firmware = json.createNestedObject("firmware");
firmware["name"] = this->_shared_interface->fwname;
firmware["version"] = this->_shared_interface->fwversion;
JsonArray& nodes = json.createNestedArray("nodes");
for (int i = 0; i < this->_shared_interface->nodes.size(); i++) {
HomieNode node = this->_shared_interface->nodes[i];
JsonObject& json_node = jsonBuffer.createObject();
json_node["id"] = node.id;
json_node["type"] = node.type;
nodes.add(json_node);
}
// 110 bytes for {"homie_version":"11.10.0","firmware":{"name":"awesome-light-great-top","version":"11.10.0-beta"},"nodes":[]}
// 60 bytes for {"id":"lightifydefoulooooo","type":"lightifydefouloooo"}, (-1 for leading ","), +1 for terminator
String jsonString;
jsonString.reserve(110 + (60 * this->_shared_interface->nodes.size()) - 1 + 1);
json.printTo(jsonString);
this->_http.send(200, FPSTR(PROGMEM_CONFIG_APPLICATION_JSON), jsonString);
}
示例3: _onDeviceInfoRequest
void BootConfig::_onDeviceInfoRequest() {
Logger.logln(F("Received device info request"));
DynamicJsonBuffer jsonBuffer = DynamicJsonBuffer(JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(2) + JSON_ARRAY_SIZE(this->_interface->registeredNodesCount) + (this->_interface->registeredNodesCount * JSON_OBJECT_SIZE(2)));
int jsonLength = 82; // {"device_id":"","homie_version":"","firmware":{"name":"","version":""},"nodes":[]}
JsonObject& json = jsonBuffer.createObject();
jsonLength += strlen(Helpers::getDeviceId());
json["device_id"] = Helpers::getDeviceId();
jsonLength += strlen(VERSION);
json["homie_version"] = VERSION;
JsonObject& firmware = json.createNestedObject("firmware");
jsonLength += strlen(this->_interface->firmware.name);
firmware["name"] = this->_interface->firmware.name;
jsonLength += strlen(this->_interface->firmware.version);
firmware["version"] = this->_interface->firmware.version;
JsonArray& nodes = json.createNestedArray("nodes");
for (int i = 0; i < this->_interface->registeredNodesCount; i++) {
jsonLength += 20; // {"id":"","type":""},
const HomieNode* node = this->_interface->registeredNodes[i];
JsonObject& jsonNode = jsonBuffer.createObject();
jsonLength += strlen(node->getId());
jsonNode["id"] = node->getId();
jsonLength += strlen(node->getType());
jsonNode["type"] = node->getType();
nodes.add(jsonNode);
}
jsonLength++; // \0
std::unique_ptr<char[]> jsonString(new char[jsonLength]);
json.printTo(jsonString.get(), jsonLength);
this->_http.send(200, FPSTR(PROGMEM_CONFIG_APPLICATION_JSON), jsonString.get());
}
示例4: _generateNetworksJson
void BootConfig::_generateNetworksJson() {
DynamicJsonBuffer generatedJsonBuffer = DynamicJsonBuffer(JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(_ssidCount) + (_ssidCount * JSON_OBJECT_SIZE(3))); // 1 at root, 3 in childrend
JsonObject& json = generatedJsonBuffer.createObject();
JsonArray& networks = json.createNestedArray("networks");
for (int network = 0; network < _ssidCount; network++) {
JsonObject& jsonNetwork = generatedJsonBuffer.createObject();
jsonNetwork["ssid"] = WiFi.SSID(network);
jsonNetwork["rssi"] = WiFi.RSSI(network);
switch (WiFi.encryptionType(network)) {
case ENC_TYPE_WEP:
jsonNetwork["encryption"] = "wep";
break;
case ENC_TYPE_TKIP:
jsonNetwork["encryption"] = "wpa";
break;
case ENC_TYPE_CCMP:
jsonNetwork["encryption"] = "wpa2";
break;
case ENC_TYPE_NONE:
jsonNetwork["encryption"] = "none";
break;
case ENC_TYPE_AUTO:
jsonNetwork["encryption"] = "auto";
break;
}
networks.add(jsonNetwork);
}
delete[] _jsonWifiNetworks;
size_t jsonBufferLength = json.measureLength() + 1;
_jsonWifiNetworks = new char[jsonBufferLength];
json.printTo(_jsonWifiNetworks, jsonBufferLength);
}
示例5: handleRequest
void handleRequest(AsyncWebServerRequest *request) {
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
int res = 400; // JSON error
// GET - get sensor value
if (request->method() == HTTP_GET && request->params() == 0) {
float val = _plugin->getValue(_sensor);
if (isnan(val))
json["value"] = JSON_NULL;
else {
json["value"] = val;
res = 200;
}
}
// POST - set sensor UUID
else if ((request->method() == HTTP_POST || request->method() == HTTP_GET)
&& request->params() == 1 && request->hasParam("uuid")) {
String uuid = request->getParam(0)->value();
if (_plugin->setUuid(uuid.c_str(), _sensor)) {
_plugin->getSensorJson(&json, _sensor);
res = 200;
}
}
jsonResponse(request, res, json);
}
示例6:
void Esp8266Configuration::write(){
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
json["wifi_ap_ssid"] = wifi_ap_ssid;
json["wifi_ap_password"] = wifi_ap_password;
json["wifi_ap_enabled"] = wifi_ap_enabled;
json["wifi_station_ssid"] = wifi_station_ssid;
json["wifi_station_password"] = wifi_station_password;
json["wifi_station_enabled"] = wifi_station_enabled;
json["mqtt_enabled"] = mqtt_enabled;
json["mqtt_host"] = mqtt_host;
json["mqtt_port"] = mqtt_port;
json["mqtt_user"] = mqtt_user;
json["mqtt_password"] = mqtt_password;
//
File configFile = SPIFFS.open("/configuration.json", "w");
if (!configFile) {
Serial.println("failed to open config file for writing");
}
//
json.printTo(Serial);
json.printTo(configFile);
configFile.close();
}
示例7: changePasswordHandler
bool simpleAuth::changePasswordHandler(
Session &session,ESP8266WebServer *s,String &p){
DynamicJsonBuffer jsonBuffer;
JsonObject& r = jsonBuffer.createObject();
r["exitcode"]="0";
r["exitmsg"]="OK password changed";
r["time"]=millis();
String callback=s->arg("callback");
if (s->arg("newpassword")==s->arg("newpassword2")){
String oldpass(s->arg("oldpassword"));
String newpass(s->arg("newpassword"));
bool chpass=this->changeUserPassword(session.user,oldpass,newpass);
if (!chpass){
r["exitcode"]="20";
r["exitmsg"]="password change failed";
}
}
else{
r["exitcode"]="10";
r["exitmsg"]="new password repeat is not identical";
}
String dstr;
r.prettyPrintTo(dstr);
s->send(200, "application/javascript",callback+"("+dstr+");");
return(true);
}
示例8: confSave
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
void CApplication::confSave()
{
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["cpuBoost"] = m_cpuBoost;
root["otaBaseUrl"] = m_otaBaseUrl.c_str();
root["emul"] = m_gpiodEmul;
root["mode"] = m_gpiodMode;
root["lock"] = m_gpiodLock;
root["disable"] = m_gpiodDisable;
root["in0Debounce"] = m_gpiodInDebounce[0];
root["in1Debounce"] = m_gpiodInDebounce[1];
root["in2Debounce"] = m_gpiodInDebounce[2];
root["in3Debounce"] = m_gpiodInDebounce[3];
root["out0DefRun"] = m_gpiodOutDefRun[0];
root["out1DefRun"] = m_gpiodOutDefRun[1];
root["out2DefRun"] = m_gpiodOutDefRun[2];
root["out3DefRun"] = m_gpiodOutDefRun[3];
root["udm0DefRun"] = m_gpiodUdmDefRun[0];
root["udm1DefRun"] = m_gpiodUdmDefRun[1];
// write to file
String strRoot;
root.printTo(strRoot);
fileSetContent(CAPP_CONF_FILE, strRoot);
} // confSave
示例9:
TEST(JsonVariant_As_Tests, ObjectAsJsonObject) {
DynamicJsonBuffer buffer;
JsonObject& arr = buffer.createObject();
JsonVariant variant = arr;
ASSERT_EQ(&arr, &variant.as<JsonObject&>());
ASSERT_EQ(&arr, &variant.as<JsonObject>()); // <- shorthand
}
示例10:
TEST(StdStream, JsonObjectSubscript) {
std::ostringstream os;
DynamicJsonBuffer jsonBuffer;
JsonObject& object = jsonBuffer.createObject();
object["key"] = "value";
os << object["key"];
ASSERT_EQ("\"value\"", os.str());
}
示例11:
JsonObject& Record<T>::toJson()
{
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root.set<long>("t", timestamp);
root.set<T>("v", value);
return root;
}
示例12: sendPing
/********************************************************************
sendPing keeps the websocket connection alive by pinging slack
********************************************************************/
void ArduinoSlackBot::sendPing() {
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["type"] = "ping";
root["id"] = nextCmdId++;
String json;
root.printTo(json);
webSocket.sendTXT(json);
}
示例13:
TEST(JsonVariant_As_Tests, ObjectAsString) {
DynamicJsonBuffer buffer;
JsonObject& obj = buffer.createObject();
obj["key"] = "value";
JsonVariant variant = obj;
ASSERT_EQ(String("{\"key\":\"value\"}"), variant.as<String>());
}
示例14: sendMsg
/********************************************************************
sendMsg sends a message back to slack on a specific channel
********************************************************************/
void ArduinoSlackBot::sendMsg(const char *channel,const char *msg) {
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["type"] = "message";
root["id"] = nextCmdId++;
root["text"] = msg;
root["channel"] = channel;
String json;
root.printTo(json);
webSocket.sendTXT(json);
}
示例15: _generateNetworksJson
void BootConfig::_generateNetworksJson() {
DynamicJsonBuffer generatedJsonBuffer = DynamicJsonBuffer(JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(this->_ssidCount) + (this->_ssidCount * JSON_OBJECT_SIZE(3))); // 1 at root, 3 in childrend
JsonObject& json = generatedJsonBuffer.createObject();
int jsonLength = 15; // {"networks":[]}
JsonArray& networks = json.createNestedArray("networks");
for (int network = 0; network < this->_ssidCount; network++) {
jsonLength += 36; // {"ssid":"","rssi":,"encryption":""},
JsonObject& jsonNetwork = generatedJsonBuffer.createObject();
jsonLength += WiFi.SSID(network).length();
jsonNetwork["ssid"] = WiFi.SSID(network);
jsonLength += 4;
jsonNetwork["rssi"] = WiFi.RSSI(network);
jsonLength += 4;
switch (WiFi.encryptionType(network)) {
case ENC_TYPE_WEP:
jsonNetwork["encryption"] = "wep";
break;
case ENC_TYPE_TKIP:
jsonNetwork["encryption"] = "wpa";
break;
case ENC_TYPE_CCMP:
jsonNetwork["encryption"] = "wpa2";
break;
case ENC_TYPE_NONE:
jsonNetwork["encryption"] = "none";
break;
case ENC_TYPE_AUTO:
jsonNetwork["encryption"] = "auto";
break;
}
networks.add(jsonNetwork);
}
jsonLength++; // \0
delete[] this->_jsonWifiNetworks;
this->_jsonWifiNetworks = new char[jsonLength];
json.printTo(this->_jsonWifiNetworks, jsonLength);
}