本文整理汇总了C++中StaticJsonBuffer::createArray方法的典型用法代码示例。如果您正苦于以下问题:C++ StaticJsonBuffer::createArray方法的具体用法?C++ StaticJsonBuffer::createArray怎么用?C++ StaticJsonBuffer::createArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StaticJsonBuffer
的用法示例。
在下文中一共展示了StaticJsonBuffer::createArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: collectData
/**
* Collect all sensors' data
*
* @param port_numbers
* The port numbers of sensors
*/
String Farmy::collectData(int port_numbers[])
{
StaticJsonBuffer<JSON_BUFFER_SIZE> jsonBuffer;
JsonArray& array = jsonBuffer.createArray();
int i = 0;
while(port_numbers[i]) {
JsonObject& object = array.createNestedObject();
object["num"] = port_numbers[i];
object["value"] = fetch(port_numbers[i]);
++i;
}
// TODO: DHT11 is a basic, ultra low-cost digital temperature and humidity sensor
// send both DHT11 sensor data
int DHT11_NUM = 4;
FarmyDHT dht = FarmyDHT(DHT11_NUM);
float temperature = dht.fetch_temperature();
delay(1000);
JsonObject& dht_object = array.createNestedObject();
dht_object["num"] = 4;
dht_object["value"] = temperature;
char data[JSON_BUFFER_SIZE];
array.printTo(data, sizeof(data));
Serial.print("Collected sensors' data are:");
Serial.println(data);
return data;
}
示例2:
TEST(StaticJsonBuffer_CreateArray_Tests, ArrayDoesntGrowWhenFull) {
StaticJsonBuffer<JSON_ARRAY_SIZE(1)> json;
JsonArray &array = json.createArray();
array.add("hello");
array.add("world");
EXPECT_EQ(1, array.size());
}
示例3: sizeof
TEST(JsonArray_CopyFrom_Tests, OneDimension_JsonBufferTooSmall) {
const size_t SIZE = JSON_ARRAY_SIZE(2);
StaticJsonBuffer<SIZE> jsonBuffer;
JsonArray& array = jsonBuffer.createArray();
char json[32];
int source[] = {1, 2, 3};
bool ok = array.copyFrom(source);
ASSERT_FALSE(ok);
array.printTo(json, sizeof(json));
ASSERT_STREQ("[1,2]", json);
}
示例4: run_iterator_test
static void run_iterator_test() {
StaticJsonBuffer<JSON_ARRAY_SIZE(2)> jsonBuffer;
JsonArray &array = jsonBuffer.createArray();
array.add(12);
array.add(34);
TIterator it = array.begin();
TIterator end = array.end();
EXPECT_NE(end, it);
EXPECT_EQ(12, it->template as<int>());
EXPECT_EQ(12, static_cast<int>(*it));
++it;
EXPECT_NE(end, it);
EXPECT_EQ(34, it->template as<int>());
EXPECT_EQ(34, static_cast<int>(*it));
++it;
EXPECT_EQ(end, it);
}
示例5: collectData
String Farmy::collectData(int input_pins[])
{
StaticJsonBuffer<200> jsonBuffer;
JsonArray& array = jsonBuffer.createArray();
int i = 0;
while(input_pins[i]) {
JsonObject& object = array.createNestedObject();
object["pin"] = input_pins[i];
object["value"] = check(input_pins[i]);
++i;
}
char data[JSON_BUFFER];
array.printTo(data, sizeof(data));
Serial.println("\n\nCollected json data: ----------------------");
Serial.println(data);
Serial.println();
String str = data;
return data;
}
示例6: TEST_CASE
// Copyright Benoit Blanchon 2014-2017
// MIT License
//
// Arduino JSON library
// https://bblanchon.github.io/ArduinoJson/
// If you like this project, please add a star!
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("StaticJsonBuffer::createArray()") {
SECTION("GrowsWithArray") {
StaticJsonBuffer<JSON_ARRAY_SIZE(2)> json;
JsonArray &array = json.createArray();
REQUIRE(JSON_ARRAY_SIZE(0) == json.size());
array.add("hello");
REQUIRE(JSON_ARRAY_SIZE(1) == json.size());
array.add("world");
REQUIRE(JSON_ARRAY_SIZE(2) == json.size());
}
SECTION("SucceedWhenBigEnough") {
StaticJsonBuffer<JSON_ARRAY_SIZE(0)> json;
JsonArray &array = json.createArray();
REQUIRE(array.success());
}