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


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

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

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

示例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";
开发者ID:kosmonout,项目名称:GarageDoor,代码行数:31,代码来源:unsigned_char.cpp

示例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;
    }
  }
}
开发者ID:TEchlin,项目名称:swarm-mothership,代码行数:101,代码来源:pfsm.cpp


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