Example #1
0
File: json.c Project: yairgd/nodes
/**
 * Created  07/25/2015
 * @brief   creates new json_value_t structure
 * @param   
 * @return 0 - success,1 fail  
 */
json_value_t * json_array11()
{
	json_value_t *json_value= malloc(sizeof(json_value_t));
	json_value->type = JS_ARRAY;
	json_array_init ( &json_value->u.array);
	return json_value;
}
Example #2
0
File: parson.c Project: sduclos/S52
static JSON_Value * json_value_init_array(void) {
    JSON_Value *new_value = (JSON_Value*)parson_malloc(sizeof(JSON_Value));
    if (!new_value) { return NULL; }
    new_value->type = JSONArray;
    new_value->value.array = json_array_init();
    if (!new_value->value.array) { parson_free(new_value); return NULL; }
    return new_value;
}
Example #3
0
int main()
{
	JSON_Object root;
	JSON_Array arr;
	JSON_String *str;

	json_object_init(&root);

	json_object_set(&root, "a", json_string_new("str123"));
	//json_object_debug_hash(&root);
	json_object_set(&root, "b", json_number_new(123));
	//json_object_debug_hash(&root);

	json_array_init(&arr);
	json_array_append(&arr, json_boolean_true());
	json_array_append(&arr, json_boolean_true());
	json_array_append(&arr, json_boolean_false());
	json_array_append(&arr, json_null());

	json_object_set(&root, "c", &arr);
	//json_object_debug_hash(&root);
	str = json_value_to_string(&root, 0);
	json_value_unref(&root);

	json_print(json_string_cstr(str));
	json_value_unref(str);

#if 0
#   define print_size(T) printf("Size of '" #T "': %lu\n", sizeof(T))
	printf("==================================\n");
	print_size(JSON_Value);
	print_size(JSON_Null);
	print_size(JSON_Boolean);
	print_size(JSON_Number);
	print_size(JSON_String);
	print_size(JSON_Array);
	print_size(JSON_Object);
#endif

	return 0;
}