本文整理汇总了C++中DynamicJsonBuffer::parseObject方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicJsonBuffer::parseObject方法的具体用法?C++ DynamicJsonBuffer::parseObject怎么用?C++ DynamicJsonBuffer::parseObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicJsonBuffer
的用法示例。
在下文中一共展示了DynamicJsonBuffer::parseObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadJsonParam
//Load config from Json file in SPIFFS
boolean loadJsonParam(const char *service) {
File configFile = SPIFFS.open("/config/config.json", "r");
if (!configFile) {
Serial.println("ERROR: Failed to open config file (loadJsonParam)");
return (boolean) false;
}
size_t size = configFile.size();
if (size > 1024) {
Serial.println("ERROR: Config file size is too large (loadJsonParam)");
return (boolean) false;
}
std::unique_ptr<char[]> buf(new char[size]);
configFile.readBytes(buf.get(), size);
DynamicJsonBuffer jsonBuffer;
JsonObject &json = jsonBuffer.parseObject(buf.get());
if (!json.success()) {
Serial.println("ERROR: Failed to parse config file (loadJsonParam)");
return (boolean) false;
}
boolean config = json[service]["enabled"];
if (config) {
return (boolean) true;
}
return (boolean) false;
}
示例2: parseResponse
/********************************************************************
parse the websocket json and look for a message type
********************************************************************/
void ArduinoSlackBot::parseResponse(char *payload) {
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(payload);
if (root.success()) {
if (root.containsKey("type")) {
slackMsg.type = root["type"];
PRINTLN(slackMsg.type);
PRINT("free heap size:");
PRINTLN(ESP.getFreeHeap());
if (strcasecmp(slackMsg.type, "message") == 0) {
slackMsg.channel = root["channel"];
slackMsg.user = root["user"];
slackMsg.text = root["text"];
slackMsg.timestamp = root["ts"];
slackMsg.team = root["team"];
PRINTLN("parseCommands");
parseCmds();
}
}
} else {
PRINTLN("parse fail");
}
}
示例3: saveJsonConfig
boolean saveJsonConfig(const char *service, const char *param, boolean status) {
File configFile = SPIFFS.open("/config/config.json", "r");
if (!configFile) {
Serial.println("ERROR: Failed to open config file (saveJsonConfig)");
return (boolean) false;
}
size_t size = configFile.size();
if (size > 1024) {
Serial.println("ERROR: Config file size is too large (saveJsonConfig)");
return (boolean) false;
}
std::unique_ptr<char[]> buf(new char[size]);
configFile.readBytes(buf.get(), size);
DynamicJsonBuffer jsonBuffer;
JsonObject &json = jsonBuffer.parseObject(buf.get());
if (!json.success()) {
Serial.println("ERROR: Failed to parse config file (saveJsonConfig)");
return (boolean) false;
}
configFile.close();
JsonObject &nested = json[service];
nested.set(param, status);
configFile = SPIFFS.open("/config/config.json", "w+");
json.prettyPrintTo(configFile);
return (boolean) true;
}
示例4: begin
void ThingSpeakClass::begin() //loads settings from json file....
{
String values = "";
File f = SPIFFS.open("/cloudgen.json", "r");
if (!f) {
DebugPrintln("thingspeak config not found");
}
else { //file exists;
values = f.readStringUntil('\n'); //read json
f.close();
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(values); //parse weburl
if (!root.success())
{
DebugPrintln("parseObject() thingspeak failed");
return;
}
if (root["spkurl"].asString() != "") { //verify good json info
thingSpeakURL = root["spkurl"].asString();
thingWriteKey = root["spkwkey"].asString();
thingInterval = String(root["spkint"].asString()).toInt();
TalkBackID = root["tkbid"].asString();
TalkBackKey = root["tkbkey"].asString();
talkBackInterval = String(root["tkbint"].asString()).toInt();
if (String(root["status"].asString()).toInt() == 1) ThingEnabled = true; else ThingEnabled = false;
if (String(root["tbstatus"].asString()).toInt() == 1) TalkBackEnabled = true; else TalkBackEnabled = false;
DebugPrintln("ThingSpeak Starting....");
}
} //file exists;
}
示例5: loadConfig
MeteoConfig loadConfig()
{
DynamicJsonBuffer jsonBuffer;
MeteoConfig cfg;
if (fileExist(METEO_CONFIG_FILE))
{
int size = fileGetSize(METEO_CONFIG_FILE);
char* jsonString = new char[size + 1];
fileGetContent(METEO_CONFIG_FILE, jsonString, size + 1);
JsonObject& root = jsonBuffer.parseObject(jsonString);
JsonObject& network = root["network"];
cfg.NetworkSSID = String((const char*)network["ssid"]);
cfg.NetworkPassword = String((const char*)network["password"]);
JsonObject& correction = root["correction"];
cfg.AddT1 = correction["T1"];
cfg.AddT2 = correction["T2"];
cfg.AddTZ = correction["TZ"];
JsonObject& trigger = root["trigger"];
cfg.Trigger = (TriggerType)(int)trigger["type"];
cfg.RangeMin = trigger["min"];
cfg.RangeMax = trigger["max"];
delete[] jsonString;
}
else
{
cfg.NetworkSSID = WIFI_SSID;
cfg.NetworkPassword = WIFI_PWD;
}
return cfg;
}
示例6: SendProbesToHM
void GlobalsClass::SendProbesToHM(String fname) { //sends Probes info to HM
String values = "";
String hmsg;
File f = SPIFFS.open(fname, "r");
if (f) { // we could open the file
values = f.readStringUntil('\n'); //read json
f.close();
//WRITE CONFIG TO HeaterMeter
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(values); //parse json data
if (!root.success())
{
DebugPrintln("parseObject() failed");
return;
}
//const char* sensor = root["sensor"];
//long time = root["time"];
//double latitude = root["data"][0];
//double longitude = root["data"][1]; }
qCon.println(String("/set?pn0=") + root["p0name"].asString()); delay(comdelay);
qCon.println(String("/set?pn1=") + root["p1name"].asString()); delay(comdelay);
qCon.println(String("/set?pn2=") + root["p2name"].asString()); delay(comdelay);
qCon.println(String("/set?pn3=") + root["p3name"].asString()); delay(comdelay);
//Set offsets
hmsg = String("/set?po=") + root["p0off"].asString() + "," + root["p1off"].asString() + "," + root["p2off"].asString() + "," + root["p3off"].asString();
qCon.println(hmsg); delay(comdelay);
DebugPrintln(hmsg);
//Set Probe coeff.
hmsg = String("/set?pc0=") + root["p0a"].asString() + "," + root["p0b"].asString() + "," + root["p0c"].asString() + "," + root["p0r"].asString() + "," + root["p0trm"].asString();
qCon.println(hmsg); delay(comdelay);
DebugPrintln(hmsg);
hmsg = String("/set?pc1=") + root["p1a"].asString() + "," + root["p1b"].asString() + "," + root["p1c"].asString() + "," + root["p1r"].asString() + "," + root["p1trm"].asString();
qCon.println(hmsg); delay(comdelay);
DebugPrintln(hmsg);
hmsg = String("/set?pc2=") + root["p2a"].asString() + "," + root["p2b"].asString() + "," + root["p2c"].asString() + "," + root["p2r"].asString() + "," + root["p2trm"].asString();
qCon.println(hmsg); delay(comdelay);
DebugPrintln(hmsg);
hmsg = String("/set?pc3=") + root["p3a"].asString() + "," + root["p3b"].asString() + "," + root["p3c"].asString() + "," + root["p3r"].asString() + "," + root["p3trm"].asString();
qCon.println(hmsg); delay(comdelay);
DebugPrintln(hmsg);
//Set Alarm offsets
hmsg = String("/set?al=") + root["p0all"].asString() + "," + root["p0alh"].asString() + "," + root["p1all"].asString() + "," + root["p1alh"].asString() + "," + root["p2all"].asString() + "," + root["p2alh"].asString() + "," + root["p3all"].asString() + "," + root["p3alh"].asString();
qCon.println(hmsg); delay(comdelay);
DebugPrintln(hmsg);
qCon.println("/set?tt=Web Settings,Updated!!"); delay(comdelay);
qCon.println("/save?"); delay(comdelay);
} //open file success
}
示例7:
void Esp8266Configuration::writeConfiguration(const char* configuration){
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.parseObject(configuration);
json.printTo(Serial);
File configFile = SPIFFS.open("/configuration.json", "w");
if (!configFile) {
Serial.println("failed to open config file for writing");
}
//
json.printTo(configFile);
configFile.close();
}
示例8: commandReceived
void commandReceived(char* topic, byte* payload, unsigned int length) {
StructureCommand command;
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char*)payload);
if(root.success()) {
command.name = root["name"];
command.time = root["$time"];
command.payload = &(root["payload"].asObject());
StructureDevice::commandCallback(&command);
}
}
示例9: SendHeatGeneralToHM
void GlobalsClass::SendHeatGeneralToHM(String fname) { //sends general info to HM
String values = "";
String hmsg;
File f = SPIFFS.open(fname, "r");
if (f) { // we could open the file
values = f.readStringUntil('\n'); //read json
f.close();
//WRITE CONFIG TO HeaterMeter
//fBuf(sbuf,"/set?sp=%iF",299); //format command;
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(values); //parse weburl
if (!root.success())
{
DebugPrintln("parseObject() failed");
return;
}
//const char* sensor = root["sensor"];
//long time = root["time"];
//double latitude = root["data"][0];
//double longitude = root["data"][1]; }
//set PID
qCon.println(String("/set?pidb=") + root["pidb"].asString()); delay(comdelay);
qCon.println(String("/set?pidp=") + root["pidp"].asString()); delay(comdelay);
qCon.println(String("/set?pidi=") + root["pidi"].asString()); delay(comdelay);
qCon.println(String("/set?pidd=") + root["pidd"].asString()); delay(comdelay);
//Set Fan info /set?fn=FL,FH,SL,SH,Flags,MSS,FAF,SAC
hmsg = String("/set?fn=") + root["minfan"].asString() + "," + root["maxfan"].asString() + "," + root["srvlow"].asString() + "," + root["srvhi"].asString() + "," + root["fanflg"].asString() +
root["maxstr"].asString() + "," + root["fanflr"].asString() + "," + root["srvcl"].asString();
qCon.println(hmsg); delay(comdelay);
DebugPrintln(hmsg);
//Set Display props
hmsg = String("/set?lb=") + root["blrange"].asString() + "," + root["hsmode"].asString() + "," + root["ledcfg"].asString();
qCon.println(hmsg); delay(comdelay);
DebugPrintln(hmsg);
//Set Lid props
hmsg = String("/set?ld=") + root["lidoff"].asString() + "," + root["liddur"].asString();
qCon.println(hmsg); delay(comdelay);
DebugPrintln(hmsg);
qCon.println("/set?tt=Web Settings,Updated!!"); delay(comdelay);
qCon.println("/save?"); delay(comdelay);
} //open file success
}
示例10: EE_LoadData
bool EE_LoadData(void) {
bool ret = false;
char data[EE_SIZE];
uint16_t i;
DEBUG_PRINT("EEPROM loading...\n");
for (i = 0; i < EE_SIZE; i++) {
yield();
data[i] = EEPROM.read(i);
// DEBUG_PRINT("%c", data[i]);
}
DEBUG_PRINT("\n");
DynamicJsonBuffer jsonBuffer;
JsonObject &root = jsonBuffer.parseObject(data);
// Test if parsing succeeds.
if (root.success() == 1) {
const char *ssid = root[FPSTR("ssid")];
DEBUG_PRINT("ssid: %s\n", ssid);
const char *password = root[FPSTR("password")];
DEBUG_PRINT("password: %s\n", password);
const char *uid = root[FPSTR("uid")];
DEBUG_PRINT("uid: %s\n", uid);
const char *domain = root[FPSTR("domain")];
DEBUG_PRINT("domain: %s\n", domain);
const char *nodename = root[FPSTR("nodename")];
DEBUG_PRINT("nodename: %s\n", nodename);
if ((ssid != NULL) && (password != NULL) && (uid != NULL) &&
(domain != NULL) && (nodename != NULL)) {
ee_ssid = String(ssid);
ee_password = String(password);
ee_uid = String(uid);
ee_domain = String(domain);
ee_nodename = String(nodename);
DEBUG_PRINT("EEPROM ok\n");
ret = true;
} else {
DEBUG_PRINT("EEPROM content not ok\n");
}
} else {
DEBUG_PRINT("parseObject() failed\n");
}
return ret;
}
示例11: confLoad
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
void CApplication::confLoad()
{
DynamicJsonBuffer jsonBuffer;
if (!confExists())
confSave();
if (confExists()) {
int size = fileGetSize(CAPP_CONF_FILE);
char* strJson = new char[size + 1];
fileGetContent(CAPP_CONF_FILE, strJson, size + 1);
JsonObject& root = jsonBuffer.parseObject(strJson);
m_cpuBoost = root["cpuBoost"];
m_otaBaseUrl = (const char *)root["otaBaseUrl"];
m_gpiodEmul = root["emul"];
m_gpiodMode = root["mode"];
m_gpiodLock = root["lock"];
m_gpiodDisable = root["disable"];
m_gpiodInDebounce[0] = root["in0Debounce"];
m_gpiodInDebounce[1] = root["in1Debounce"];
m_gpiodInDebounce[2] = root["in2Debounce"];
m_gpiodInDebounce[3] = root["in3Debounce"];
m_gpiodOutDefRun[0] = root["out0DefRun"];
m_gpiodOutDefRun[1] = root["out1DefRun"];
m_gpiodOutDefRun[2] = root["out2DefRun"];
m_gpiodOutDefRun[3] = root["out3DefRun"];
m_gpiodUdmDefRun[0] = root["udm0DefRun"];
m_gpiodUdmDefRun[1] = root["udm1DefRun"];
delete[] strJson;
}
} // confLoad
示例12: onAjaxConnect
void onAjaxConnect(HttpRequest &request, HttpResponse &response)
{
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST");
response.setHeader("Access-Control-Allow-Headers", "Content-Type, X-Requested-With");
// parse the json-string from request body
DynamicJsonBuffer jsonBuffer;
String bodyString = request.getBody();
int stringLength = request.getContentLength();
char* requestJson = new char[stringLength + 1];
strcpy(requestJson, bodyString.c_str());
JsonObject& body = jsonBuffer.parseObject(requestJson);
// get parameter form json
String newNetwork = body["network"].asString();
String newPassword = body["password"].asString();
AppSettings.channelKey = body["channelKey"].asString();
AppSettings.save();
// json for response
JsonObjectStream* stream = new JsonObjectStream();
JsonObject& responseJson = stream->getRoot();
// try connecting
network = newNetwork;
password = newPassword;
debugf("CONNECT TO: %s %s", network.c_str(), password.c_str());
connectionTimer.initializeMs(1200, makeConnection).startOnce();
// response always connected because we don't know yet if connecting was successful
responseJson["status"] = (bool) true;
responseJson["connected"] = true;
response.sendJsonObject(stream);
}
示例13: parseTextMessage
void parseTextMessage(AsyncWebSocketClient * client, uint8_t * data, size_t len)
{
DynamicJsonBuffer jsonBuffer;
// parse possible json files
if( data[0] =='{' && data[len - 1] == '}' )
{
// let's parse the json file
Serial.println("JSON STR RECEIVED!");
char tmp[len + 1];
memcpy(tmp, (char *)data, len);
tmp[len] = '\0';
JsonObject& root = jsonBuffer.parseObject(tmp);
// ########################
// Wifi configuration file
// ########################
if ( root.containsKey("mode") )
{
if ( strcmp((const char*)root["mode"], "ap") == 0 )
{
Serial.println("AP");
storage.wifisett.setSSID((const char*)root["ssid"]);
storage.wifisett.setPwd((const char*)root["pwd"]);
storage.wifisett.enableSoftAP();
}
else if ( strcmp((const char*)root["mode"], "sta") == 0 )
{
Serial.println("STA");
storage.wifisett.setClientSSID((const char*)root["ssid"]);
storage.wifisett.setClientPwd((const char*)root["pwd"]);
// set mode to STA
storage.wifisett.enableClient();
}
}
// #########################
// Set Clock
// #########################
if (root.containsKey("setclock") )
{
JsonObject& rootsetclock = root.get("setclock");
if ( rootsetclock.containsKey("type") && ( strcmp((const char*)rootsetclock["type"], "ntp") == 0 ) )
{
// get ntp time
opaq_controller.syncClock();
}
else
{
// get values from json
RtcDateTime tmp = RtcDateTime( rootsetclock["year"], rootsetclock["month"], rootsetclock["day"], rootsetclock["hour"], rootsetclock["minute"], rootsetclock["second"]);
opaq_controller.getCom().setClock(tmp);
}
}
// #########################
// Get Clock
// #########################
if (root.containsKey("getclock") )
{
// let's send the clock values
JsonObject& tmp_root = jsonBuffer.createObject();
JsonObject& conf = tmp_root.createNestedObject("realtimeclock");
RtcDateTime date;
opaq_controller.getCom().getClock(date); // [TODO] this can fail
conf["second"] = date.Second();
conf["minute"] = date.Minute();
conf["hour"] = date.Hour();
conf["day"] = date.Day();
conf["month"] = date.Month();
conf["year"] = date.Year();
String tmp = "";
tmp_root.printTo(tmp);
client->text(tmp);
}
// ################
// Filename getter
// ################
if (root.containsKey("filename") )
{
String content = "";
sendFile(SPIFFS, root["filename"], content);
//.........这里部分代码省略.........
示例14: processCommand
void CommandExecutor::processCommand(Command cmdCommand)
{
debugf("Received Command, size = %d,cmd = %s",cmdCommand.cmdString.length(),cmdCommand.cmdString.c_str());
if (cmdCommand.cmdName == "")
{
// Need to extract command from inputline
// Check if we have a json input
DynamicJsonBuffer jsonBuffer;
JsonObject& cmdRoot = jsonBuffer.parseObject(cmdCommand.cmdString);
if (cmdRoot.success())
{
debugf("ParseObject() -> cmdString is Json object");
if (cmdRoot.containsKey("cmd"))
{
cmdCommand.cmdName = cmdRoot["cmd"].asString();
}
else
{
if (cmdRoot.begin() != cmdRoot.end()) // There is at least one key
{
cmdCommand.cmdName = cmdRoot.begin()->key;
}
}
}
else // First word of cmdString is cmdCommand
{
int cmdLen = cmdCommand.cmdString.indexOf(' ');
if (cmdLen == -1)
{
cmdCommand.cmdName = cmdCommand.cmdString;
}
else
{
cmdCommand.cmdName = cmdCommand.cmdString.substring(0,cmdLen);
}
}
}
debugf("CommandExecutor : executing command %s",cmdCommand.cmdName.c_str());
CommandDelegate cmdDelegate = commandHandler.getCommandDelegate(cmdCommand.cmdName);
if ((!cmdDelegate.commandProcessDelegate) && (!cmdDelegate.commandFunction))
{
commandOutput->printf("Command not found, cmd = '");
commandOutput->printf(cmdCommand.cmdString.c_str());
commandOutput->printf("'\r\n");
}
else
{
if (cmdDelegate.commandProcessDelegate)
{
cmdDelegate.commandProcessDelegate(cmdCommand,commandOutput);
}
else
{
cmdDelegate.commandFunction(cmdCommand.cmdString,commandOutput);
}
}
commandOutput->flush();
if (commandHandler.getVerboseMode() == VERBOSE)
{
commandOutput->printf(commandHandler.getCommandPrompt().c_str());
commandOutput->flush();
}
}
示例15: tryParseObject
bool tryParseObject(const char *json) {
DynamicJsonBuffer buffer;
char s[256];
strcpy(s, json);
return buffer.parseObject(s, _nestingLimit).success();
}