Skip to content

How to create the correct format of JSON? #1606

Open
@luigitofano

Description

@luigitofano

{
    "root": {
        "A": [
            [
                [
                    [
                        1.0000008344650269,
                        -9.0,
                        8.742284762774943e-08
                    ],
                    [
                        4.0,
                        -1.9999996423721313,
                        3.4969113471561286e-07
                    ],
                    [
                        8.999999046325684,
                        12.000000953674316,
                        7.868048896852997e-07
                    ],
                    [
                        14.0,
                        -1.9999988079071045,
                        1.2239188436069526e-06
                    ],
                    [
                        17.0,
                        -8.999998092651367,
                        1.486187329646782e-06
                    ]
                ]
            ],
            [
                [
                    [
                        4.0,
                        -1.9999996423721313,
                        3.4969113471561286e-07
                    ],
                    [
                        14.0,
                        -1.9999988079071045,
                        1.2239188436069526e-06
                    ],
                    [
                        14.0,
                        -1.9999988079071045,
                        1.2239188436069526e-06
                    ],
                    [
                        4.0,
                        -1.9999996423721313,
                        3.4969113471561286e-07
                    ]
                ]
            ]
        ]
    }
}


HersheyText::CharacterDataSet HersheyText::loadCharacterDataSet() {
    CharacterDataSet dataSet;

    // Check if root is an object
    if (!root.isObject()) {
        std::cerr << "Error: 'root' value is not an object." << std::endl;
        return dataSet;
    }

    for (const auto& characterKey : root.getMemberNames()) {
        CharacterData characterData;
        characterData.character = characterKey;

        const Json::Value& characterJson = root[characterKey];
        if (characterJson.isArray()) {
            const Json::Value& characterJson = root[characterKey];
            if (!characterJson.isArray()) { //<-- Unhandled exception
                std::cerr << "Warning: Data for character '" << characterKey << "' is not an array." << std::endl;
                continue;
            }
            parsePolyline(characterJson, characterData.polylines);

        }

        dataSet.characters.push_back(characterData);
    }

    return dataSet;
}

So far the format of this JSON leads to an unhandled exception somewhere on or near the line marked with '<--'... How to solve this? What should the JSON format look like?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions