Пример #1
0
double traverse_sajson(const sajson::value &v)
{
	double x = 0;
	switch (v.get_type())
	{
		case sajson::TYPE_DOUBLE:
			x += v.get_double_value();
			break;
		case sajson::TYPE_INTEGER:
			x += v.get_integer_value();
			break;
		case sajson::TYPE_ARRAY:
			for (size_t i = 0; i < v.get_length(); ++i)
			{
				x += traverse_sajson(v.get_array_element(i));
			}
			break;
		case sajson::TYPE_OBJECT:
			for (size_t i = 0; i < v.get_length(); ++i)
			{
				x += traverse_sajson(v.get_object_value(i));
			}
			break;
		default:
			return 0;
	}
	return x;
}
Пример #2
0
static bool hasJsonValue(sajson::value jsonObject, const char* key, sajson::type expectedType) {
	size_t index = jsonObject.find_object_key(sajson::literal(key));
	if (index == jsonObject.get_length()) {
		return false;
	}
	sajson::value value = jsonObject.get_object_value(index);
	return value.get_type() == expectedType;
}
Пример #3
0
static sajson::value getJsonValue(sajson::value jsonObject, const char* key) {
	size_t index = jsonObject.find_object_key(sajson::literal(key));
	return jsonObject.get_object_value(index);
}