Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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]);
}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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)));
	}*/
}