How to get the JSON parser to work?



  • Hello,

    I'm trying to parse some JSON data here. The code so far is simple enough...

    const maxon::JsonParserRef jsonParser = maxon::JsonParserRef::Create() iferr_ignore();
    maxon::DataDictionary responseData;
    jsonParser.Read(response.body, maxon::JSONPARSERFLAGS::NONE, responseData) iferr_ignore();
    

    Compiling in Xcode 10.1 bring up the error:

    Showing Recent Issues
    /Applications/MAXON/Cinema 4D R21/frameworks/core.framework/source/maxon/delegate.h:792:10: Type 'maxon::DataDictionary' does not provide a call operator

    Commenting out the last line of the example code lets the error disappear.
    How does this work?

    Thanks & greetings from Berlin,
    Frank

    PS: Some example code, especially for the newer stuff in die API would be fantastic ;-)

    PPS: The complete error output:

    In file included from /Applications/MAXON/Cinema 4D R21/plugins/myPlugin/source/some_sourcefile.cpp:9:
    In file included from ../../frameworks/cinema.framework/source/c4d.h:14:
    In file included from ../../frameworks/cinema.framework/source/c4d_basebitmap.h:13:
    In file included from ../../frameworks/cinema.framework/source/ge_math.h:120:
    In file included from ../../frameworks/core.framework/source/maxon/vector.h:5:
    In file included from ../../frameworks/core.framework/source/maxon/string.h:4:
    In file included from ../../frameworks/core.framework/source/maxon/interfacebase.h:6:
    In file included from ../../frameworks/core.framework/source/maxon/datatypebase.h:4:
    In file included from ../../frameworks/core.framework/source/maxon/collection.h:5:
    ../../frameworks/core.framework/source/maxon/delegate.h:792:10: error: type 'maxon::DataDictionary' does not provide a call operator
    return (*static_cast<T*>(objectPtr))(std::forward<ARGS>(args)...);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../frameworks/core.framework/source/maxon/delegate.h:760:49: note: in instantiation of function template specialization 'maxon::Delegate<maxon::Result<bool> (const maxon::DataDictionary &)>::FunctorStub<maxon::DataDictionary>' requested here

    new (this) DelegateBase(std::forward<FN>(fn), FunctorStub<FunctorType>, UtilityStub<FunctorType>);
    ^
    ../../frameworks/core.framework/source/maxon/delegate.h:407:3: note: in instantiation of function template specialization 'maxon::Delegate<maxon::Result<bool> (const maxon::DataDictionary &)>::ConstructFrom<maxon::DataDictionary &>' requested here
    ConstructFrom(std::forward<FN>(fn));
    ^
    /Applications/MAXON/Cinema 4D R21/plugins/myPlugin/source/some_sourcefile.cpp:617:66: note: in instantiation of function template specialization 'maxon::Delegate<maxon::Result<bool> (const maxon::DataDictionary &)>::Delegate<maxon::DataDictionary &, void>' requested here
    jsonParser.Read(response.body, maxon::JSONPARSERFLAGS::NONE, responseData) iferr_ignore();
    ^



  • Hi Frank, thanks for reaching out us.

    With regard to the JSON parser, I've used its implementation in the examples showing how the new licensing system can work with 3rd party plugins.
    There's a bunch of code in on our Github repo:

    • writing JSON is here;
    • reading JSON is here.

    Hope both snippets could serve the scope.

    Greeting from Italy!
    Riccardo



  • Cool, hadn't seen that one yet. Thanks!



  • A little follow-up question, as I don't really understand it from the provided example code:

    How would I read nested values from a JSON? For example:

    {
        "some_object" : {
            "some_data": {
                 "title": "foo"
            }
        }
    }
    

    How would I read json["some_object"]["some_data"]["title"] ?

    Thanks in advance!

    Cheers,
    Frank



  • Hi Frank,

    actually you can deal with by checking the type of the stored value and read it as a maxon::DataDictionary

    .
    ..
    ...
    	if (value.GetType() == maxon::GetDataType<maxon::DataDictionary>())
    	{
    		nestedDataDict = value.Get<maxon::DataDictionary>() iferr_return;
    	}
    ...
    ..
    ,
    

    Hope this helps.
    Riccardo


Log in to reply