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


C++ JsonObject::AddArray方法代码示例

本文整理汇总了C++中JsonObject::AddArray方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonObject::AddArray方法的具体用法?C++ JsonObject::AddArray怎么用?C++ JsonObject::AddArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonObject的用法示例。


在下文中一共展示了JsonObject::AddArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HandlePluginInfo

/*
 * Handle the plugin description response.
 * @param response the HTTPResponse that is associated with the request.
 * @param description the plugin description.
 * @param error an error string.
 */
void OladHTTPServer::HandlePluginInfo(
    HTTPResponse *response,
    string description,
    const OlaCallbackClient::PluginState &state,
    const string &error) {
  if (!error.empty()) {
    m_server.ServeError(response, error);
    return;
  }
  string escaped_description = description;
  Escape(&escaped_description);

  JsonObject json;
  json.Add("description", description);
  json.Add("name", state.name);
  json.Add("enabled", state.enabled);
  json.Add("active", state.active);
  json.Add("preferences_source", state.preferences_source);
  JsonArray *plugins = json.AddArray("conflicts_with");
  vector<OlaPlugin>::const_iterator iter = state.conflicting_plugins.begin();
  for (; iter != state.conflicting_plugins.end(); ++iter) {
    JsonObject *plugin = plugins->AppendObject();
    plugin->Add("active", iter->IsActive());
    plugin->Add("id", iter->Id());
    plugin->Add("name", iter->Name());
  }

  response->SetNoCache();
  response->SetContentType(HTTPServer::CONTENT_TYPE_PLAIN);
  response->SendJson(json);
  delete response;
}
开发者ID:mlba-team,项目名称:open-lighting,代码行数:38,代码来源:OladHTTPServer.cpp

示例2: HandlePluginList

/*
 * Handle the plugin list callback
 * @param response the HTTPResponse that is associated with the request.
 * @param plugins a list of plugins
 * @param error an error string.
 */
void OladHTTPServer::HandlePluginList(HTTPResponse *response,
                                     const vector<OlaPlugin> &plugins,
                                     const string &error) {
  if (!error.empty()) {
    m_server.ServeError(response, error);
    return;
  }

  JsonObject *json = new JsonObject();

  // fire off the universe request now. the main server is running in a
  // separate thread.
  bool ok = m_client.FetchUniverseList(
      NewSingleCallback(this,
                        &OladHTTPServer::HandleUniverseList,
                        response,
                        json));

  if (!ok) {
    m_server.ServeError(response, K_BACKEND_DISCONNECTED_ERROR);
    delete json;
    return;
  }

  JsonArray *plugins_json = json->AddArray("plugins");
  vector<OlaPlugin>::const_iterator iter;
  for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
    JsonObject *plugin = plugins_json->AppendObject();
    plugin->Add("name", iter->Name());
    plugin->Add("id", iter->Id());
  }
}
开发者ID:mlba-team,项目名称:open-lighting,代码行数:38,代码来源:OladHTTPServer.cpp

示例3: HandlePluginList

/*
 * Handle the plugin list callback
 * @param response the HTTPResponse that is associated with the request.
 * @param plugins a list of plugins
 * @param error an error string.
 */
void OladHTTPServer::HandlePluginList(HTTPResponse *response,
                                      const client::Result &result,
                                      const vector<OlaPlugin> &plugins) {
  if (!result.Success()) {
    m_server.ServeError(response, result.Error());
    return;
  }

  JsonObject *json = new JsonObject();

  // fire off the universe request now. the main server is running in a
  // separate thread.
  m_client.FetchUniverseList(
      NewSingleCallback(this,
                        &OladHTTPServer::HandleUniverseList,
                        response,
                        json));

  JsonArray *plugins_json = json->AddArray("plugins");
  vector<OlaPlugin>::const_iterator iter;
  for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
    JsonObject *plugin = plugins_json->AppendObject();
    plugin->Add("name", iter->Name());
    plugin->Add("id", iter->Id());
  }
}
开发者ID:nip3o,项目名称:open-lighting,代码行数:32,代码来源:OladHTTPServer.cpp

示例4: HandlePluginInfo

/**
 * @brief Handle the plugin description response.
 * @param response the HTTPResponse that is associated with the request.
 * @param description the plugin description
 * @param result the result of the API call.
 * @param state the state of the plugin.
 */
void OladHTTPServer::HandlePluginInfo(HTTPResponse *response,
                                      string description,
                                      const client::Result &result,
                                      const ola::client::PluginState &state) {
  if (!result.Success()) {
    m_server.ServeError(response, result.Error());
    return;
  }

  string escaped_description = description;
  // Replace \n before passing in so we get \\n out the far end
  ReplaceAll(&escaped_description, "\n", "\\n");

  JsonObject json;
  json.Add("description", escaped_description);
  json.Add("name", state.name);
  json.Add("enabled", state.enabled);
  json.Add("active", state.active);
  json.Add("preferences_source", state.preferences_source);
  JsonArray *plugins = json.AddArray("conflicts_with");
  vector<OlaPlugin>::const_iterator iter = state.conflicting_plugins.begin();
  for (; iter != state.conflicting_plugins.end(); ++iter) {
    JsonObject *plugin = plugins->AppendObject();
    plugin->Add("active", iter->IsActive());
    plugin->Add("id", iter->Id());
    plugin->Add("name", iter->Name());
  }

  response->SetNoCache();
  response->SetContentType(HTTPServer::CONTENT_TYPE_PLAIN);
  response->SendJson(json);
  delete response;
}
开发者ID:steczol,项目名称:ola,代码行数:40,代码来源:OladHTTPServer.cpp

示例5: AsString

/*
 * Return the section as a string.
 */
string JsonSection::AsString() const {
  JsonObject json;

  json.Add("refresh", m_allow_refresh);
  json.Add("error", m_error);
  if (!m_save_button_text.empty())
    json.Add("save_button", m_save_button_text);

  JsonArray *items = json.AddArray("items");
  vector<const GenericItem*>::const_iterator iter = m_items.begin();
  for (; iter != m_items.end(); ++iter) {
    JsonObject *item = items->AppendObject();
    (*iter)->PopulateItem(item);
  }
  return JsonWriter::AsString(json);
}
开发者ID:basileus,项目名称:ola,代码行数:19,代码来源:JsonSections.cpp

示例6: testComplexObject

/*
 * Test a complex object.
 */
void JsonTest::testComplexObject() {
  JsonObject object;
  object.Add("age", 10);
  object.Add("name", "simon");
  object.Add("male", true);

  JsonArray *array = object.AddArray("lucky numbers");
  array->Append(2);
  array->Append(5);

  string expected = (
      "{\n"
      "  \"age\": 10,\n"
      "  \"lucky numbers\": [2, 5],\n"
      "  \"male\": true,\n"
      "  \"name\": \"simon\"\n"
      "}");
  OLA_ASSERT_EQ(expected, JsonWriter::AsString(object));
}
开发者ID:mlba-team,项目名称:open-lighting,代码行数:22,代码来源:JsonTest.cpp


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