2020
2121#include < multipass/simple_streams_index.h>
2222
23- #include < QJsonDocument>
24- #include < QJsonObject>
23+ #include < nlohmann/json.hpp>
2524
2625#include < stdexcept>
2726
27+ using json = nlohmann::json;
2828namespace mp = multipass;
2929
3030namespace
3131{
32- QJsonObject parse_index (const QByteArray& json)
32+ json parse_index (std::string_view json)
3333{
34- QJsonParseError parse_error;
35- auto doc = QJsonDocument::fromJson (json, &parse_error);
36- if (doc.isNull ())
37- throw std::runtime_error (parse_error.errorString ().toStdString ());
38-
39- if (!doc.isObject ())
34+ auto doc = json::parse (json);
35+ if (!doc.is_object ())
4036 throw std::runtime_error (" invalid index object" );
4137
42- auto index = doc.object ()[ " index" ]. toObject ( );
43- if (index.isEmpty ())
38+ auto index = doc.at ( " index" );
39+ if (index.empty ())
4440 throw std::runtime_error (" No index found" );
4541
4642 return index;
@@ -49,16 +45,15 @@ QJsonObject parse_index(const QByteArray& json)
4945
5046mp::SimpleStreamsIndex mp::SimpleStreamsIndex::fromJson (const QByteArray& json)
5147{
52- auto index = parse_index (json);
48+ auto index = parse_index (json. toStdString () );
5349
54- for (QJsonValueRef value : index)
50+ for (auto && [_, value] : index. items () )
5551 {
56- auto entry = value.toObject ();
57- if (entry[" datatype" ] == " image-downloads" )
52+ if (value.at (" datatype" ) == " image-downloads" )
5853 {
59- auto path_entry = entry[ " path" ] ;
60- auto date_entry = entry[ " updated" ] ;
61- return {path_entry. toString ( ), date_entry. toString ( )};
54+ auto path_entry = value. at ( " path" ). get <std::string>() ;
55+ auto date_entry = value. at ( " updated" ). get <std::string>() ;
56+ return {QString::fromStdString (path_entry ), QString::fromStdString (date_entry )};
6257 }
6358 }
6459
0 commit comments