PIJSON::new* now accept optional initial fields

This commit is contained in:
2025-07-09 12:41:23 +03:00
parent 7b52f6d70d
commit ed3d4c4217
5 changed files with 72 additions and 51 deletions

View File

@@ -204,16 +204,21 @@
//!
PIJSON PIJSON::newObject() {
PIJSON PIJSON::newObject(const PIVariantMap & fields) {
PIJSON ret;
ret.c_type = Object;
auto it = fields.makeIterator();
while (it.next())
ret[it.key()] = it.value();
return ret;
}
PIJSON PIJSON::newArray() {
PIJSON PIJSON::newArray(const PIVariantVector & fields) {
PIJSON ret;
ret.c_type = Array;
for (const auto & i: fields)
ret << i;
return ret;
}
@@ -325,6 +330,15 @@ PIJSON & PIJSON::operator<<(const PIJSON & element) {
}
PIJSON & PIJSON::operator<<(const PIVariant & element) {
c_type = Array;
PIJSON e;
e = element;
c_array << e;
return *this;
}
PIJSON & PIJSON::operator=(const PIJSON & v) {
c_type = v.c_type;
c_value = v.c_value;