I receive \" at the beginning and end of every message?

Hi There,

When I send a message using Photon Chat C++ SDK on iOS, I receive "\ in the beginning and end of the string I sent. This is how I convert the Object to string : message.toString().UTF8Representation().cstr() . Is there anything wrong that I'm doing?

Thanks,

Özden

Comments

  • Kaiserludi
    Kaiserludi admin
    edited November 2015
    Hi @Ozden79.

    This behavior is by design. toString() is intended to be used for debugging and logging purposes and stringifies everything it is called on. This way you can for example get a string representation of a Dictionary, Hashtable, Array and so on, which can be very useful to look at them in your debug output and analyze their structure and content and check if it meets your expectations. As everything that gets returned by toString() is a string, data that has already been a string before getting stringified gets enclosed in "" so that strings can be easier distinguished from other data types. Calling toString() directly on a string is not particularly useful, but if you call it on a container that may contain a mix of different types of items, then that container will call toString() on all its items.

    toString() is NOT intended to be used for the actual data retrieval. Think about it: How would you retrieve for example an int? There is no toInt() function.
    To access the payload of an Object instance you call getDataCopy() on a KeyObject or ValueObject interpretation of that instance:
    
    ExitGames::Common::JString myString = ExitGames::Common::ValueObject<ExitGames::Common::JString>(message).getDataCopy();
    int myInt = ExitGames::Common::ValueObject<int>(message).getDataCopy();
    
    If you don't know the type of the contained data of a certain Object instance at compile time, then you can check it at run time by comparing the return value of Object::getType() against the various constants in Common::TypeCode:
    
    	switch(message.getType())
    	{
    	case ExitGames::Common::TypeCode::STRING:
    		{
    			ExitGames::Common::JString myString = ExitGames::Common::ValueObject<ExitGames::Common::JString>(message).getDataCopy();
    			printf("UTF16(Windows)/UTF32(Unix): %ls   UTF8: %s\n", myString.cstr(), myString.UTF8Representation().cstr());
    		}
    		break;
    	case ExitGames::Common::TypeCode::INTEGER:
    		{
    			int myInt = ExitGames::Common::ValueObject<int>(message).getDataCopy();
    			printf("%d\n", myInt);
    		}
    		break;
    	default:
    		EGLOG(ExitGames::Common::DebugLevel::ERRORS, L"Oh no! An unexpected type.");
    	}
    
  • Thanks a lot for this detailed instruction. I used "toString()" as this was what I've seen in your example app so never thought it could be the problem.