1

I have a string returned from a web service containing a JSON string. Some of the properties in the string are base 64 encoded. Trouble is they are not base64 encoded in a consistent way. As per https://en.wikipedia.org/wiki/Base64#Implementations_and_history there is some variation in base64 encoding. I know what I'm expecting, and I need to preprocess a certain property value before decoding an deserializing it. I'm looking for the hooks in JsonConvert.DeserializeObject() or JsonSerializerSettings in order to do that.

To be clear, the json I need to deserialize includes multiple properties with base 64 encoding. Some have / + and padding, others have _ - and no padding. The latter causes an exception:

"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. "

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Martin Alley
  • 121
  • 1
  • 9
  • Those weird looking encodings are base-64 url encoded string. a modification to base-64 to allow for safe transfer in urls. Check the [**URL applications**](https://en.wikipedia.org/wiki/Base64#URL_applications) section of the wiki you linked – Nkosi Sep 30 '16 at 12:11
  • See this answer http://stackoverflow.com/a/26354677/782754 – Adrian Iftode Sep 30 '16 at 12:15

1 Answers1

0

I created a custom JsonConverter and introduced it via JsonSerializerSettings Thanks Martin

Martin Alley
  • 121
  • 1
  • 9