How to serialize to JSON in Qt

前端 未结 4 615
梦如初夏
梦如初夏 2021-02-07 13:00

How can I JSON serialize a QVariant (or other type of data) in Qt. I don\'t want to use an external third party library like QJson

4条回答
  •  [愿得一人]
    2021-02-07 13:50

    Just to mention, as of Qt5, JSON is officially supported:

    JSON Support in Qt

    QVariant id(1), name("John Doe");
    QJsonObject json;
    
    json["Name"] = name.toString();
    json.insert("id", id.toInt());
    

提交回复
热议问题