Commit 925d75f1 authored by Volker Krause's avatar Volker Krause
Browse files

Strip of trailing non-JSON content after embedded train formation data

The station name seems to be inserted there in some cases, which confuses
the JSON parser.
parent ad69b89f
{"SFormation":{"leavingDirection":"left","TrainGroups":{"TrainGroup":[{"destination":"Spiez","Car":[{"type":"2","section":"A","CarAttributes":{"Attr":[{"code":"AbteilRollstuhl"},{"code":"NiederflurEinstieg"}]}},{"type":"1","section":"B","CarAttributes":{"Attr":{"code":"NiederflurEinstieg"}}},{"type":"2","section":"B","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}},{"type":"2","section":"B","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}},{"type":"2","section":"C","CarAttributes":{"Attr":[{"code":"AbteilRollstuhl"},{"code":"NiederflurEinstieg"}]}},{"type":"1","section":"C","CarAttributes":{"Attr":{"code":"NiederflurEinstieg"}}},{"type":"2","section":"C","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}},{"type":"2","section":"C","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}}]},{"destination":"Brig","Car":[{"type":"2","section":"D","CarAttributes":{"Attr":[{"code":"AbteilRollstuhl"},{"code":"NiederflurEinstieg"}]}},{"type":"1","section":"D","CarAttributes":{"Attr":{"code":"NiederflurEinstieg"}}},{"type":"2","section":"D","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}},{"type":"2","section":"E","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}}]},{"destination":"Zweisimmen","Car":[{"type":"2","section":"E","CarAttributes":{"Attr":[{"code":"AbteilRollstuhl"},{"code":"NiederflurEinstieg"}]}},{"type":"1","section":"F","CarAttributes":{"Attr":{"code":"NiederflurEinstieg"}}},{"type":"2","section":"F","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}},{"type":"2","section":"F","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}}]}]},"Legend":{"LegendItem":[{"id":"1","refersTo":"type","Text":{"$":"Reisezugwagen 1. Klasse"}},{"id":"2","refersTo":"type","Text":{"$":"Reisezugwagen 2. Klasse"}},{"id":"AbteilVeloPl","refersTo":"code","Text":{"$":"Veloplatz: ohne Reservation"}},{"id":"AbteilRollstuhl","refersTo":"code","Text":{"$":"Rollstuhlplatz mit Rollstuhl-WC"}},{"id":"NiederflurEinstieg","refersTo":"code","Text":{"$":"Niederflureinstieg"}},{"id":"Fahrtrichtung","refersTo":"code","Text":{"$":"Fahrtrichtung"}}]},"LegendSortOrder":{"$":"LK|1|2|WR|W1|W2|FA|AbteilFamilien|CC|WL|WC|-|AbteilBusiness|AbteilVeloRes|AbteilVeloPl|AbteilKinderwagen|AbteilRollstuhl|NiederflurEinstieg|Reisegruppe|Fahrtrichtung|HFS_WG_NUM"},"Info":{"$":"\\n "}}}
{"SFormation":{"leavingDirection":"left","TrainGroups":{"TrainGroup":[{"destination":"Spiez","Car":[{"type":"2","section":"A","CarAttributes":{"Attr":[{"code":"AbteilRollstuhl"},{"code":"NiederflurEinstieg"}]}},{"type":"1","section":"B","CarAttributes":{"Attr":{"code":"NiederflurEinstieg"}}},{"type":"2","section":"B","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}},{"type":"2","section":"B","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}},{"type":"2","section":"C","CarAttributes":{"Attr":[{"code":"AbteilRollstuhl"},{"code":"NiederflurEinstieg"}]}},{"type":"1","section":"C","CarAttributes":{"Attr":{"code":"NiederflurEinstieg"}}},{"type":"2","section":"C","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}},{"type":"2","section":"C","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}}]},{"destination":"Brig","Car":[{"type":"2","section":"D","CarAttributes":{"Attr":[{"code":"AbteilRollstuhl"},{"code":"NiederflurEinstieg"}]}},{"type":"1","section":"D","CarAttributes":{"Attr":{"code":"NiederflurEinstieg"}}},{"type":"2","section":"D","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}},{"type":"2","section":"E","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}}]},{"destination":"Zweisimmen","Car":[{"type":"2","section":"E","CarAttributes":{"Attr":[{"code":"AbteilRollstuhl"},{"code":"NiederflurEinstieg"}]}},{"type":"1","section":"F","CarAttributes":{"Attr":{"code":"NiederflurEinstieg"}}},{"type":"2","section":"F","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}},{"type":"2","section":"F","CarAttributes":{"Attr":[{"code":"AbteilVeloPl"},{"code":"NiederflurEinstieg"}]}}]}]},"Legend":{"LegendItem":[{"id":"1","refersTo":"type","Text":{"$":"Reisezugwagen 1. Klasse"}},{"id":"2","refersTo":"type","Text":{"$":"Reisezugwagen 2. Klasse"}},{"id":"AbteilVeloPl","refersTo":"code","Text":{"$":"Veloplatz: ohne Reservation"}},{"id":"AbteilRollstuhl","refersTo":"code","Text":{"$":"Rollstuhlplatz mit Rollstuhl-WC"}},{"id":"NiederflurEinstieg","refersTo":"code","Text":{"$":"Niederflureinstieg"}},{"id":"Fahrtrichtung","refersTo":"code","Text":{"$":"Fahrtrichtung"}}]},"LegendSortOrder":{"$":"LK|1|2|WR|W1|W2|FA|AbteilFamilien|CC|WL|WC|-|AbteilBusiness|AbteilVeloRes|AbteilVeloPl|AbteilKinderwagen|AbteilRollstuhl|NiederflurEinstieg|Reisegruppe|Fahrtrichtung|HFS_WG_NUM"},"Info":{"$":"\\n "}}} (Bern)
......@@ -155,7 +155,8 @@ static void parseTrainFormationCars(std::vector<VehicleSection> &vehicleSections
Vehicle HafasVehicleLayoutParser::parseTrainFormation(const QByteArray &data)
{
QJsonParseError parserError;
const auto sformation = QJsonDocument::fromJson(data, &parserError).object().value(QLatin1String("SFormation")).toObject();
const auto jsonEndIdx = data.lastIndexOf('}') + 1;
const auto sformation = QJsonDocument::fromJson(data.mid(0, jsonEndIdx), &parserError).object().value(QLatin1String("SFormation")).toObject();
if (parserError.error != QJsonParseError::NoError) {
qDebug() << parserError.errorString();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment