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(); }
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 << "}"; } }
bool JsonParser::extractFalse(JsonNode &node) { if (!extractLiteral("false")) return false; node.Bool() = false; return true; }
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; }
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; }