Ejemplo n.º 1
0
QVariant toVariant(const JsonNode & node)
{
	switch(node.getType())
	{
		break;
	case JsonNode::JsonType::DATA_NULL:
		return QVariant();
		break;
	case JsonNode::JsonType::DATA_BOOL:
		return QVariant(node.Bool());
		break;
	case JsonNode::JsonType::DATA_FLOAT:
		return QVariant(node.Float());
		break;
	case JsonNode::JsonType::DATA_STRING:
		return QVariant(QString::fromUtf8(node.String().c_str()));
		break;
	case JsonNode::JsonType::DATA_VECTOR:
		return JsonToList(node.Vector());
		break;
	case JsonNode::JsonType::DATA_STRUCT:
		return JsonToMap(node.Struct());
	}
	return QVariant();
}
Ejemplo n.º 2
0
void JsonWriter::writeNode(const JsonNode &node)
{
	switch(node.getType())
	{
		break; case JsonNode::DATA_NULL:
			out << "null";

		break; case JsonNode::DATA_BOOL:
			if (node.Bool())
				out << "true";
			else
				out << "false";

		break; case JsonNode::DATA_FLOAT:
			out << node.Float();

		break; case JsonNode::DATA_STRING:
			writeString(node.String());

		break; case JsonNode::DATA_VECTOR:
			out << "[" << "\n";
			writeContainer(node.Vector().begin(), node.Vector().end());
			out << prefix << "]";

		break; case JsonNode::DATA_STRUCT:
			out << "{" << "\n";
			writeContainer(node.Struct().begin(), node.Struct().end());
			out << prefix << "}";
	}
}
Ejemplo n.º 3
0
bool JsonParser::extractFalse(JsonNode &node)
{
	if (!extractLiteral("false"))
		return false;

	node.Bool() = false;
	return true;
}
Ejemplo n.º 4
0
JsonNode toJson(QVariant object)
{
	JsonNode ret;

	if (object.canConvert<QVariantMap>())
		ret.Struct() = VariantToMap(object.toMap());
	else if (object.canConvert<QVariantList>())
		ret.Vector() = VariantToList(object.toList());
	else if (static_cast<QMetaType::Type>(object.type()) == QMetaType::QString)
		ret.String() = object.toString().toUtf8().data();
	else if (static_cast<QMetaType::Type>(object.type()) == QMetaType::Bool)
		ret.Bool() = object.toBool();
	else if (object.canConvert<double>())
		ret.Float() = object.toFloat();

	return ret;
}
Ejemplo n.º 5
0
void CModInfo::loadLocalData(const JsonNode & data)
{
	bool validated = false;
	enabled = true;
	checksum = 0;
	if (data.getType() == JsonNode::DATA_BOOL)
	{
		enabled = data.Bool();
	}
	if (data.getType() == JsonNode::DATA_STRUCT)
	{
		enabled   = data["active"].Bool();
		validated = data["validated"].Bool();
		checksum  = strtol(data["checksum"].String().c_str(), nullptr, 16);
	}

	if (enabled)
		validation = validated ? PASSED : PENDING;
	else
		validation = validated ? PASSED : FAILED;
}