1

In swift how does the JSOnEncoder() encode Data data types?

Here is my struct that i am encoding

    struct VoiceQueryRequest: Codable {
          var type:String = "voiceQuery"
          var audioOutput:Data = Data()
    }

Im using websockets to send the encoded json object to a node server. Im using URLSessionWebSocketTask.Message.data to create the websockets message.

I need to understand how the audioOutput: Data propertie is encoded so that i can decode the object on the server.

Chris Maley
  • 157
  • 1
  • 8

1 Answers1

1

JSONEncoder has a dataEncodingStrategy property that determines how Data properties are encoded. The default is to encode it as a base 64 string.

dan
  • 9,695
  • 1
  • 42
  • 40