本文整理汇总了C++中StaticJsonBuffer::parseArray方法的典型用法代码示例。如果您正苦于以下问题:C++ StaticJsonBuffer::parseArray方法的具体用法?C++ StaticJsonBuffer::parseArray怎么用?C++ StaticJsonBuffer::parseArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StaticJsonBuffer
的用法示例。
在下文中一共展示了StaticJsonBuffer::parseArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadDeviceIFTTT
//設定を設定サーバーから読み出す
void CogleMasterConfig::loadDeviceIFTTT(void){
String url = String(COFIG_SERVER_API_DEVICE_IFTTT)
+"?deviceKey="
+String(deviceKey)
+"&_sort=id"
+"&_order=DESC"
+"&_end=3";
//Serial.print("url:");Serial.println(url);
char body[1024];
httpGet(url, body, 1024);
//Serial.println("body:");Serial.println(body);
Serial.println("body size:");Serial.println( String(body).length() );
//TODO:JSONでパースして内容を取得
StaticJsonBuffer<1024> jsonBuffer;
JsonArray &array = jsonBuffer.parseArray(body);
Serial.print("json size:");Serial.println(array.size());
for(int i=0;i<array.size();i++){
//Slaveは3個まで
if(i > SLAVE_COUNT) break;
JsonObject &iftttObj = array[i];
deviceIfttt[i].deviceKey = iftttObj["deviceKey"];
deviceIfttt[i].deviceSlaveId = iftttObj["deviceSlaveId"];
deviceIfttt[i].secretKey = iftttObj["secretKey"];
deviceIfttt[i].event = iftttObj["event"];
deviceIfttt[i].actionType = iftttObj["actionType"];
//Serial.print("deviceSlaveId:"); Serial.println( deviceIfttt[i].deviceSlaveId );
}
}
示例2: defined
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wvla"
#else
#define VLA_NOT_SUPPORTED
#endif
#ifndef VLA_NOT_SUPPORTED
TEST_CASE("Variable Length Array") {
SECTION("ParseArray") {
int i = 8;
char vla[i];
strcpy(vla, "[42]");
StaticJsonBuffer<JSON_ARRAY_SIZE(1)> jsonBuffer;
JsonArray& arr = jsonBuffer.parseArray(vla);
REQUIRE(true == arr.success());
}
SECTION("ParseObject") {
int i = 16;
char vla[i];
strcpy(vla, "{\"a\":42}");
StaticJsonBuffer<JSON_OBJECT_SIZE(1)> jsonBuffer;
JsonObject& obj = jsonBuffer.parseObject(vla);
REQUIRE(true == obj.success());
}
示例3: defined
// https://bblanchon.github.io/ArduinoJson/
// If you like this project, please add a star!
#include <ArduinoJson.h>
#include <catch.hpp>
#if defined(__clang__)
#define CONFLICTS_WITH_BUILTIN_OPERATOR
#endif
TEST_CASE("unsigned char string") {
SECTION("JsonBuffer::parseArray") {
unsigned char json[] = "[42]";
StaticJsonBuffer<JSON_ARRAY_SIZE(1)> jsonBuffer;
JsonArray& arr = jsonBuffer.parseArray(json);
REQUIRE(true == arr.success());
}
SECTION("JsonBuffer::parseObject") {
unsigned char json[] = "{\"a\":42}";
StaticJsonBuffer<JSON_OBJECT_SIZE(1)> jsonBuffer;
JsonObject& obj = jsonBuffer.parseObject(json);
REQUIRE(true == obj.success());
}
SECTION("JsonVariant constructor") {
unsigned char value[] = "42";
示例4: update
//.........这里部分代码省略.........
resetResetTime();
resetReadyCheck();
state = IDLE;
} else if(delayComplete()) {
Serial.println(F("PFSM: Status timed out"));
state = IDLE;
}
}
if(state == FETCH_COMMAND) {
rest.get(command_endpoint);
// prepare for response
rest.getResponse(NULL, 0, true);
delay_end = millis() + 1000;
state = AWAITING_COMMAND;
}
if(state == AWAITING_COMMAND) {
StaticJsonBuffer<256> jsonBuffer;
char buffer[256];
int resp;
if((resp = rest.getResponse(buffer, sizeof(buffer), false)) == HTTP_STATUS_OK) {
// parse the response
resetResetTime();
resetReadyCheck();
char* ptr = buffer;
// skip to the payload
for(uint16_t ii = 0; ii < sizeof(buffer); ++ii) {
if(buffer[ii] == '\n') {
ptr = &buffer[ii+1];
break;
}
}
JsonArray& root = jsonBuffer.parseArray(ptr);
if(!root.success()) {
Serial.print(F("PFSM: Failed to parse "));
Serial.println(ptr);
command_check = millis() + 1000;
state = IDLE;
} else {
if(root.size() == 0) {
// nothing in our queue
Serial.println(F("No commands waiting"));
command_check = millis() + 1000;
state = IDLE;
} else {
if(command.fromJson(root[0])) {
command_valid = true;
command_complete = false;
state = IDLE;
} else {
Serial.print(F("PFSM: Message invalid "));
Serial.println(buffer);
command_check = millis() + 1000;
state = IDLE;
}
}
}
} else if(delayComplete()) {
Serial.println(F("PFSM: Command request timed out"));
command_check = millis() + 1000;
state = IDLE;
}
}
if(state == ACK_COMMAND) {
StaticJsonBuffer<128> jsonBuffer;
char buffer[128];
JsonObject& obj = jsonBuffer.createObject();
obj["pid"] = swarmID();
obj["cid"] = command.cid;
obj["complete"] = true;
obj.printTo(buffer, sizeof(buffer));
rest.put(command_endpoint, buffer);
// prepare for response
rest.getResponse(NULL, 0, true);
delay_end = millis() + 1000;
state = AWAITING_ACK;
}
if(state == AWAITING_ACK) {
char buffer[128];
int resp;
if((resp = rest.getResponse(buffer, sizeof(buffer), false)) == HTTP_STATUS_OK) {
// assume we got goodness
state = IDLE;
command_valid = false;
command_complete = false;
} else if(delayComplete()) {
// this is the one case we retry forever. It's important that the mothership know that
// we did what we said we would do.
Serial.println(F("PFSM: Ack timed out"));
state = ACK_COMMAND;
}
}
}