QJsonObject object; object.insert("name", "John"); object.insert("age", 25); QJsonValue nameValue = object.take("name"); QString name = nameValue.toString(); // name = "John" QJsonValue zipValue = object.take("zip"); bool isEmpty = zipValue.isNull(); // isEmpty = true, key "zip" does not exist
QJsonObject person; person.insert("name", "Jane"); person.insert("age", 30); QJsonValue ageValue = person.take("age"); int age = ageValue.toInt(); // age = 30 person.insert("age", age + 1); // update the age value QJsonDocument doc(person); QString jsonStr = doc.toJson(QJsonDocument::Compact); // jsonStr = {"name":"Jane","age":31}Note: It is important to ensure that the QJsonValue returned by take() is not empty before using it, to avoid runtime errors.