Beispiel #1
0
static void test_string(void)
{
    JSON json = parseJSON(data, data+sizeof(data));
    JSON child = JSON_get(json, "app");
    assert(JSON_isValid(child));
    assert(JSON_type(child) == JSON_Array);
    assert(JSON_length(child) == 3);
    JSONArray *a;
    JSON *I, *E;
    int i = 0;

    JSON_ARRAY_EACH(child, a, I, E) {
        assert(JSON_isValid(JSON_get(*I, "name")));
        assert(JSON_isValid(JSON_get(*I, "line")));
        assert(JSON_isValid(JSON_get(*I, "version")));
        assert(JSON_isValid(JSON_get(*I, "flag")));
        size_t len;
        const char *name = JSON_getString(*I, "name", &len);
        int   line = JSON_getInt(*I, "line");
        double ver  = JSON_getDouble(*I, "version");
        assert(len == strlen(names[i]) && strncmp(name, names[i], len) == 0);
        assert(line == lines[i]);
        assert(ver  == versions[i]);
        fprintf(stderr, "%s %d %f\n", name, line, ver);
        i++;
    }
Beispiel #2
0
static double GetJsonFloat(KonohaContext *kctx, struct JsonBuf *jsonbuf, const char *key, size_t keylen_or_zero, double defval)
{
	JSON json = AsJSON(jsonbuf);
	if(key == NULL)
		return JSONDouble_get(json);
	return JSON_getDouble(json, key, KeyLen(key, keylen_or_zero));
}
Beispiel #3
0
//## JSONFloat JSON.getFloat(String key);
static KMETHOD kJSON_getFloat(KonohaContext *kctx, KonohaStack *sfp)
{
	JSON obj = ((kJSON *)sfp[0].asObject)->json;
	const char *key = S_text(sfp[1].asString);
	double json = JSON_getDouble(obj, key);
	KReturnFloatValue(json);
}
Beispiel #4
0
static double GetJsonFloat(KonohaContext *kctx, struct JsonBuf *jsonbuf, const char *key, size_t keylen_or_zero, double defval)
{
	if(key == NULL)
		JSONDouble_get(toJSON(jsonbuf->json_i));
	return JSON_getDouble(toJSON(jsonbuf->json_i), key, KeyLen(key, keylen_or_zero));
}