Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    R25 Json Parser Usage

    Cinema 4D SDK
    2
    3
    593
    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.
    • Danchyg1337D
      Danchyg1337
      last edited by

      Hello! I'm currently trying to transfer S24 plugin code into R25. As i see in changelog, parser_json.h is replaced with parser.h. But the usage is not clear. In the code, i was reading the string with

      jsonParser.Read(result, maxon::JSONPARSERFLAGS::NONE, dd) iferr_return;
      

      and jsonParser is

      maxon::JsonParserRef jsonParser;
      

      created like this

      auto jsonCRes = maxon::JsonParserRef::Create();
      if (jsonCRes == maxon::FAILED)
      	MessageDialog("JSON parser create fail"_s);
      jsonParser = jsonCRes.GetValue();
      

      I couldn't find anything similar to such creation in the new parser. Could you breafly explain how to create a valid ParserRef and call ReadString to convert string into dictionary?
      Thanks!

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        Hi,

        the parser interface has been changed, you have more parser, and the process is the same for each parser. Create a reference and use it.

        Parsers are declared in ParserClasses we have now json, jwt and csv parser.

        //----------------------------------------------------------------------------------------
        /// Parse a given JSON string and return the JSON data in a maxon::DataDictionary.
        /// @param[in] in_string				The string containing a JSON representation.
        /// @return											Error code if fail else the DataDictionary.
        static maxon::Result<maxon::DataDictionary> ImportJSONFromString(const maxon::String &in_string)
        {
        	iferr_scope;
        	
        	// check passed argument
        	if (in_string.IsEmpty())
        		return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION, "Passed string is empty."_s);
        	
        	// create a JSONParser reference
        	const maxon::ParserRef jsonParser = maxon::ParserClasses::JsonParser().Create() iferr_return;
        	
        	// allocate a SingleValueReceiver to store the data read from the JSONParser;
        	maxon::SingleValueReceiver<const maxon::DataDictionary&> readData;
        
        	// parse the string  and check it's containing a valid JSON structure
        	iferr (jsonParser.ReadString(in_string, maxon::PARSERFLAGS::NONE, maxon::GetUtf8DefaultDecoder(), readData))
        	{
        		// provided string is not containing a valid JSON structure
        		DiagnosticOutput("BLW >> Invalid JSON string [@]");
        		iferr_throw(err);
        	}
        
        	// return the data
        	return readData.Get().GetValue();
        }
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        Danchyg1337D 1 Reply Last reply Reply Quote 0
        • Danchyg1337D
          Danchyg1337 @Manuel
          last edited by

          @m_magalhaes Thank you!

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