var serialized = JsonConvert.SerializeObject(obj, settings);
{
"HomeId": "2925362b",
"UserId": "9ea43c30",
"Name": "Name 1",
"Description1": "VABlAHMAdABlAA==", //===> Converts to Base64 (OK)
"User": {
"UserId": "9ea43c30",
"Email": "[email protected]",
"Perfil": {
"UserId": "9ea43c30",
"Name": "Name 2",
"Description2": "dABlAHMAdABlAA==", //===> Converts to Base64 (OK)
}
}
}
//
var deserialized = JsonConvert.DeserializeObject<T>(serialized, settings); // T is class Home
{
"HomeId": "2925362b",
"UserId": "9ea43c30",
"Name": "Name 1",
"Description1": "VABlAHMAdABlAA==", //===> Don't Convert from Base64, (**Does not call the ReadJson function of ByteArrayConverter**)
"User": {
"UserId": "9ea43c30",
"Email": "[email protected]",
"Perfil": {
"UserId": "9ea43c30",
"Name": "Name 2",
"Description2": "dABlAHMAdABlAA==", //===> Convert from Base64 (OK)
}
}
}
設定
var settings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
Formatting = Formatting.Indented
};
settings.Converters.Add(new ByteArrayConverter());
それはバイトをバックに変換されませんので、説明1のプロパティは、ByteArrayConverterクラスのReadJson関数に入らないをデシリアライズ[]、別の無効な[]バイトを生成しています....
すべてのIDこの問題のea?
は、なぜあなたはすべてのコンバータを使用している見つけることができるようあなたがByteArrayConverter必要はありませんか? Json.NETは、基本的にバイト配列のためのbase64をサポートしています。[Serialization Guide:Primitive Types](http://www.newtonsoft.com/json/help/html/serializationguide.htm) – dbc
こんにちは、上記のように使用しないと$ type: "System.Byte []、mscorlib" $値: "VABlAHMAdABlAA =="という情報でバイト[]型をシリアル化しますが、デシリアライズするとエラーが表示されます:値の解析中に予期しない文字が発生しました – Anpeiron
FWIW、あなたが指定した同じ設定を使用してコンバータなしで私のためにうまくいきました。 –