快速而肮脏的解决方案:
QString s = "[[[1,2,3]],[[4,5,6],[7,8,9]],\"string\"]";
QStringList parts = s.remove("[").remove("]").split(',');
QVector<int> xval, yval;
if (parts.size() >= 6)
{
xval << parts[0].toInt() << parts[1].toInt() << parts[2].toInt();
yval << parts[3].toInt() << parts[4].toInt() << parts[5].toInt();
}
编辑:现在支持可变长度数组:
QVector<int> ToIntList(const QString& s)
{
QVector<int> result;
QStringList parts = s.trimmed().split(",");
for (int i = 0; i < parts.size(); ++i)
result << parts[i].toInt();
return result;
}
QString s = "[[[1,2,3,4,5,6, 7, 8]],[[9\n,10], [11,12,13]],\"string\"]";
QStringList lists = s.remove(" ").split("],[");
for (int i = 0; i < lists.size(); ++i)
lists[i] = lists[i].remove("[").remove("]");
QVector<int> xval, yval;
if (lists.size() >= 2)
{
xval = ToIntList(lists[0]);
yval = ToIntList(lists[1]);
}