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


C++ StaticJsonBuffer::createArray方法代码示例

本文整理汇总了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;
}
开发者ID:farmy-maker,项目名称:farmy-sdk,代码行数:39,代码来源:Farmy.cpp

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

示例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);
}
开发者ID:1125384055,项目名称:libraries,代码行数:13,代码来源:JsonArray_CopyFrom_Tests.cpp

示例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);
}
开发者ID:1125384055,项目名称:libraries,代码行数:20,代码来源:JsonArray_Iterator_Tests.cpp

示例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;
}
开发者ID:arthurbryant,项目名称:farmy,代码行数:23,代码来源:Farmy.cpp

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


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