json11 in nx_kit does not seem to parse json string properly

In Progress



  • Avatar
    James Yu

    When I change points to string array, Json::parse() is able to parse properly.

    std::string pf_err;
    std::string test = R"({"figure":{"color":"#e040fb","points":[["0.795","0.7058823529411765"],["0.785","0.9558823529411765"],["0.9483333333333334","0.961764705882353"],["0.97","0.7294117647058823"]]},"label":"aaa","showOnCamera":true})";
    printf(">>>> test: %s\n", test.c_str());
    Json js_polygon = Json::parse(test, pf_err);
    std::cout << ">>>> js_polygon = " << js_polygon.dump() << "\n";

    and the output becomes

    >>>> js_polygon = {"figure": {"color": "#e040fb", "points": [["0.795", "0.7058823529411765"], ["0.785", "0.9558823529411765"], ["0.9483333333333334", "0.961764705882353"], ["0.97", "0.7294117647058823"]]}, "label": "aaa", "showOnCamera": true}

    However, the polygon setting retrieved by "settingValue()" has points as double array.

    How do I configure json11 to make it parse double array properly?






    Comment actions Permalink
  • Avatar
    James Yu

    after updating strtod_dot() in json11.cpp, I am able to get those double values

    double strtod_dot(const char* str) {
    const size_t str_length = strspn(str, "0123456789.eE+-");

    char str_double[str_length+1] = {0};
    strncpy(str_double, str, str_length);
    double f = atof(str_double);
    return f;



    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hello James,

    I took the sample_analytics_plugin of the Metadata SDK.

    I refactored your code a little and put it into the DeviceAgent::pushUncompressedVideoFrame() method.
    You can use any other method of your choice.

    Include the <nx/kit/json.h> header file.

    Here is the code

        std::string pf_err;
    std::string test = R"({
    NX_PRINT << ">>>> test: " << test;
    nx::kit::Json js_polygon = nx::kit::Json::parse(test, pf_err);
    NX_PRINT << ">>>> js_polygon = " << js_polygon.dump();

    And here is the output. The code seems working correctly.

    Comment actions Permalink
  • Avatar
    James Yu

    Hi Andrey,

    I am experiencing something very strange. I tried to create a Json object with a double value, but the created Json object does not have the value. When I do the same thing with an integer, the created Json has the value. What happens?

    Comment actions Permalink

Please sign in to leave a comment.