本文整理汇总了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;
}
示例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());
}
}
示例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());
}
}
示例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;
}
示例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);
}
示例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));
}