PIJSON::new* now accept optional initial fields
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user