本文整理汇总了C++中JsonArray::add方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonArray::add方法的具体用法?C++ JsonArray::add怎么用?C++ JsonArray::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonArray
的用法示例。
在下文中一共展示了JsonArray::add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createObject
JsonObject createObject() {
// {"x":{"a":{"b":1}},"y":{"d":{"e":2},"g":{"h":3,"o":{"p":9}},"z":[{"i"5},{"j":6},{"l":{"m":7,"n":8}}]}
JsonObject o;
{
JsonObject x;
{
JsonObject a;
a.add("b", 1);
x.add("a", a);
}
o.add("x", x);
}
{
JsonObject y;
{
JsonObject d;
d.add("e", 2);
y.add("d", d);
}
{
JsonObject g;
g.add("h", 3);
JsonObject oo;
oo.add("p", 9);
g.add("o", oo);
y.add("g", g);
}
o.add("y", y);
}
{
JsonArray z;
{
JsonObject i;
i.add("i", 5);
z.add(i);
}
{
JsonObject j;
j.add("j", 6);
z.add(j);
}
{
JsonObject l;
JsonObject s;
s.add("m", 7);
s.add("n", 8);
l.add("l", s);
z.add(l);
}
o.add("z", z);
}
return o;
}
示例2: toJson
void History::toJson(JsonArray& json)
{
for (int i = _next(_last); i != _last; i = _next(i))
json.add(_records[i]);
json.add<unsigned short>(_records[_last]);
}
示例3: run_iterator_test
static void run_iterator_test() {
StaticJsonDocument<JSON_ARRAY_SIZE(2)> doc;
JsonArray array = doc.to<JsonArray>();
array.add(12);
array.add(34);
TIterator it = array.begin();
TIterator end = array.end();
REQUIRE(end != it);
REQUIRE(12 == it->template as<int>());
REQUIRE(12 == static_cast<int>(*it));
++it;
REQUIRE(end != it);
REQUIRE(34 == it->template as<int>());
REQUIRE(34 == static_cast<int>(*it));
++it;
REQUIRE(end == it);
}
示例4: getDirList
JsonArray* SystemFile::getDirList(int pid,int level)
{
String sql;
sql.printf("SELECT file_id,file_name FROM tb_file2 WHERE file_lname='' AND file_pid=%d ORDER BY file_name;", pid);
SQRes res = m_db->exec(sql);
JsonArray* array = new JsonArray();
while (res->next())
{
JsonHash* dir = new JsonHash();
int id = atoi(res->getColumn(0));
dir->add("id", createJson(id));
dir->add("name", createJson(res->getColumn(1)));
if (level)
{
JsonArray* child = getDirList(id, level - 1);
dir->add("child", child);
}
array->add(dir);
}
return array;
}
示例5: outFileList
void SystemFile::outFileList(Stream* s)
{
INT pid = 0;
LPCSTR methodPID = Method::GET("pid");
if(methodPID)
pid = atoi(methodPID);
String sql;
sql.printf("SELECT file_id,file_size,file_date,file_name,file_kind,file_type FROM tb_file2 WHERE file_pid=%d ORDER BY file_kind DESC,upper(file_name);", pid);
SQRes res = m_db->exec(sql);
s->setHeader("Content-type", "text/plain; charset=UTF-8");
JsonHash hash;
JsonArray* array = new JsonArray();
while (res->next())
{
INT id = atoi(res->getColumn(0));
JsonHash* file = new JsonHash();
file->add("id",createJson(id));
file->add("size", createJson(atoi(res->getColumn(1))));
file->add("date", createJson(res->getColumn(2)));
file->add("name", createJson(res->getColumn(3)));
file->add("kind", createJson(atoi(res->getColumn(4))));
file->add("type", createJson(res->getColumn(5)));
array->add(file);
}
hash.add("files", array);
String work;
hash.getString(work);
s->setHeader("Content-type", "text/plain; charset=UTF-8");
s->out(work);
/*
String sql;
sql.printf("SELECT file_id,file_size,file_date,file_name,file_kind,file_type FROM tb_file2 WHERE file_pid=%d ORDER BY file_kind DESC,upper(file_name);",pid);
SQRes res = m_db->exec(sql);
s->setHeader("Content-type","text/plain; charset=UTF-8");
s->out("file_id,file_size,file_date,file_name,file_kind,count,file_type\n");
bool flag = false;
String ids;
while(res->next())
{
if(flag)
ids.appendf(",'%s'",res->getColumn());
else
{
ids.appendf("'%s'",res->getColumn());
flag = true;
}
}
std::map<INT,INT> downloadCount;
if(m_dbLog)
{
String sql;
sql.printf("SELECT param,count(*) FROM tb_access WHERE command='DOWNLOAD' AND param IN (%s) GROUP BY param;",ids.c_str());
SQRes res = m_dbLog->exec(sql);
while(res->next())
{
downloadCount[atoi(res->getColumn(0))] = atoi(res->getColumn(1));
}
}
res->setFirst();
while(res->next())
{
INT id = atoi(res->getColumn(0));
s->printf("%d,%d,%s,%s,%d,%d,%s\n",
id,
atoi(res->getColumn(1)),
SQLSTRING(res->getColumn(2)),
SQLSTRING(res->getColumn(3)),
atoi(res->getColumn(4)),
downloadCount[id],
SQLSTRING(res->getColumn(5)));
}*/
}