Ejemplo n.º 1
0
static size_t DoJsonEach(KonohaContext *kctx, struct JsonBuf *jsonbuf, void *thunk, void (*doEach)(KonohaContext *, const char *, size_t, struct JsonBuf *, void *))
{
	size_t count = 0;
	struct JsonBuf eachbuf;
	JSON Key, Val;
	JSONObject_iterator Itr;
	JSON obj = AsJSON(jsonbuf);
	JSON_OBJECT_EACH(obj, Itr, Key, Val) {
		const char *key = JSONString_get(Key);
		size_t len      = JSONString_length(Key);
		eachbuf.json_i  = Val.bits;
		doEach(kctx, key, len, &eachbuf, thunk);
		count++;
	}
	return count;
}
Ejemplo n.º 2
0
static size_t DoJsonEach(KonohaContext *kctx, struct JsonBuf *jsonbuf, void *thunk, void (*doEach)(KonohaContext *, const char *, struct JsonBuf *, void *))
{
	size_t count = 0;
	struct JsonBuf eachbuf = {};
	void *iter = json_object_iter(jsonbuf->jsonobj);
	while(iter != NULL) {
		const char *key = json_object_iter_key(iter);
		json_t *value   = json_object_iter_value(iter);
		SetJsonBuf(&eachbuf, value);
		doEach(kctx, key, &eachbuf, thunk);
		count++;
		iter = json_object_iter_next(jsonbuf->jsonobj, iter);
	}
	FreeJson(kctx, &eachbuf);
	return count;
}
Ejemplo n.º 3
0
static size_t DoJsonEach(KonohaContext *kctx, struct JsonBuf *jsonbuf, void *thunk, void (*doEach)(KonohaContext *, const char *, struct JsonBuf *, void *))
{
	size_t count = 0;
	struct JsonBuf eachbuf = {};
	{
		JSON Key, Val;
		JSONObject_iterator Itr;
		JSON obj = toJSON(jsonbuf->json_i);
		JSON_OBJECT_EACH(obj, Itr, Key, Val) {
			const char *key = Key.str->str;
			eachbuf.json_i = Val.bits;
			doEach(kctx, key, &eachbuf, thunk);
			count++;
		}
	}
	return count;
}