Qt 对 json字串的解析

这是json串

[
    {
        "ServerIP": "P1:10.2.41.20:10.2.41.20:001"
    },
    {
        "ServerIP": "pc01:10.2.41.82:10.2.41.82:001"
    },
    {
        "ServerIP": "q-P1:10.2.41.88:10.2.41.88:111"
    },
    {
        "ServerIP": "e-pc01:10.2.41.105:10.2.41.105:001"
    },
    {
        "ServerIP": "pc16:10.2.41.58:10.2.41.58:001"
    },
    {
        "ServerIP": "e-pc01:10.2.41.119:10.2.41.119:001"
    },
    {
        "ServerIP": "-P1:10.2.41.81:10.2.41.81:001"
    },
    {
        "ServerIP": "p1:10.2.41.93:10.2.41.93:001"
    }
]

QString strServerJsonResults = 上面那串字
QByteArray bit = strServerJsonResults.toUtf8();
QJsonParseError parseError;
QJsonDocument jsonDocument = QJsonDocument::fromJson(bit, &parseError);
QJsonArray json_array = jsonDocument.array();
QString serverIp = "ServerIP";
for (int i = 0; i < json_array.size(); ++i)
{
    QString oneProjectInfo;
    QJsonObject json = json_array.at(i).toObject();
    oneProjectInfo = json.value(serverIp).toString();
    QString s(oneProjectInfo);
    QStringList sL = s.split(":");
}

你可能感兴趣的:(C++,json字串解析,Qt,qt,c++,json)