Skip to content

How to create the correct format of JSON? #1606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
luigitofano opened this issue Apr 5, 2025 · 0 comments
Open

How to create the correct format of JSON? #1606

luigitofano opened this issue Apr 5, 2025 · 0 comments

Comments

@luigitofano
Copy link


{
    "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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant