Esempio n. 1
0
static kbool_t RetrieveJsonKeyValue(KonohaContext *kctx, struct JsonBuf *jsonbuf, const char *key, size_t keylen_or_zero, struct JsonBuf *newbuf)
{
	json_t *obj = json_object_get(jsonbuf->jsonobj, key);
	if(obj != NULL) {
		SetJsonBuf(newbuf, obj);
		return true;
	}
	return false;
}
Esempio n. 2
0
static kbool_t RetrieveJsonArrayAt(KonohaContext *kctx, struct JsonBuf *jsonbuf, size_t index, struct JsonBuf *otherbuf)
{
	json_t *obj = json_array_get(jsonbuf->jsonobj, index);
	if(obj != NULL) {
		SetJsonBuf(otherbuf, obj);
		return true;
	}
	return false;
}
Esempio 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 = {};
	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;
}