当前位置: 首页>>代码示例>>C++>>正文


C++ DynamicJsonBuffer::createObject方法代码示例

本文整理汇总了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);
}
开发者ID:TobiasN82,项目名称:Pufferspeicher,代码行数:28,代码来源:configuration.cpp

示例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);
}
开发者ID:enavarro222,项目名称:homie-esp8266,代码行数:28,代码来源:BootConfig.cpp

示例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());
}
开发者ID:DavidStacer,项目名称:homie-esp8266,代码行数:35,代码来源:BootConfig.cpp

示例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);
}
开发者ID:euphi,项目名称:homie-esp8266,代码行数:35,代码来源:BootConfig.cpp

示例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);
  }
开发者ID:andig,项目名称:vzero,代码行数:27,代码来源:webserver.cpp

示例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();
}
开发者ID:ivankravets,项目名称:Esp8266Configuration,代码行数:25,代码来源:Esp8266Configuration.cpp

示例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);
}
开发者ID:it-guru,项目名称:ThIN,代码行数:29,代码来源:pack.cpp

示例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
开发者ID:sim0njo,项目名称:wiControl,代码行数:34,代码来源:app_conf.cpp

示例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
}
开发者ID:FernandoGarcia,项目名称:Ferduino_with_webcontrol_beta,代码行数:8,代码来源:JsonVariant_As_Tests.cpp

示例10:

TEST(StdStream, JsonObjectSubscript) {
  std::ostringstream os;
  DynamicJsonBuffer jsonBuffer;
  JsonObject& object = jsonBuffer.createObject();
  object["key"] = "value";
  os << object["key"];
  ASSERT_EQ("\"value\"", os.str());
}
开发者ID:chris153002,项目名称:esp8266Switch,代码行数:8,代码来源:StdStream.cpp

示例11:

JsonObject& Record<T>::toJson()
{
  DynamicJsonBuffer jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root.set<long>("t", timestamp);
  root.set<T>("v", value);
  return root;
}
开发者ID:4m1g0,项目名称:IOT_tfg,代码行数:8,代码来源:History.cpp

示例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);
}
开发者ID:nullboundary,项目名称:ArduinoSlack,代码行数:12,代码来源:ArduinoSlackBot.cpp

示例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>());
}
开发者ID:AugustoPujato,项目名称:ArduinoJson,代码行数:9,代码来源:JsonVariant_As_Tests.cpp

示例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);
}
开发者ID:nullboundary,项目名称:ArduinoSlack,代码行数:16,代码来源:ArduinoSlackBot.cpp

示例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);
}
开发者ID:DavidStacer,项目名称:homie-esp8266,代码行数:41,代码来源:BootConfig.cpp


注:本文中的DynamicJsonBuffer::createObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。