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


C++ JsonArray::AppendObject方法代码示例

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


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

示例1: HandleCandidatePorts

/*
 * Handle the list of candidate ports
 * @param response the HTTPResponse that is associated with the request.
 * @param devices the possbile devices & ports
 * @param error an error string.
 */
void OladHTTPServer::HandleCandidatePorts(
    HTTPResponse *response,
    const vector<class OlaDevice> &devices,
    const string &error) {
  if (!error.empty()) {
    m_server.ServeError(response, error);
    return;
  }

  vector<OlaDevice>::const_iterator iter = devices.begin();
  vector<OlaInputPort>::const_iterator input_iter;
  vector<OlaOutputPort>::const_iterator output_iter;

  JsonArray json;
  for (; iter != devices.end(); ++iter) {
    const vector<OlaInputPort> &input_ports = iter->InputPorts();
    for (input_iter = input_ports.begin(); input_iter != input_ports.end();
         ++input_iter) {
      JsonObject *obj = json.AppendObject();
      PortToJson(obj, *iter, *input_iter, false);
    }

    const vector<OlaOutputPort> &output_ports = iter->OutputPorts();
    for (output_iter = output_ports.begin();
         output_iter != output_ports.end(); ++output_iter) {
      JsonObject *obj = json.AppendObject();
      PortToJson(obj, *iter, *output_iter, true);
    }
  }

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

示例2: 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

示例3: 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

示例4: SetValue

void SelectItem::SetValue(JsonObject *item) const {
  JsonArray *options = item->AddArray("value");
  vector<pair<string, string> >::const_iterator iter = m_values.begin();
  for (; iter != m_values.end(); ++iter) {
    JsonObject *option = options->AppendObject();
    option->Add("label", iter->first);
    option->Add("value", iter->second);
  }
}
开发者ID:basileus,项目名称:ola,代码行数:9,代码来源:JsonSections.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


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