Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to get the JSON parser to work?

    Cinema 4D SDK
    r21 c++
    2
    5
    876
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • fwilleke80F
      fwilleke80
      last edited by fwilleke80

      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();
      ^

      www.frankwilleke.de
      Only asking personal code questions here.

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by

        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

        1 Reply Last reply Reply Quote 1
        • fwilleke80F
          fwilleke80
          last edited by

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

          www.frankwilleke.de
          Only asking personal code questions here.

          1 Reply Last reply Reply Quote 0
          • fwilleke80F
            fwilleke80
            last edited by

            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

            www.frankwilleke.de
            Only asking personal code questions here.

            1 Reply Last reply Reply Quote 0
            • r_giganteR
              r_gigante
              last edited by

              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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post