C# プロジェクトで JSON ライブラリとして使用ServiceStack.Text
しており、それを使用してファイルから文字列を逆シリアル化しようとしていますTypeSerializer.DeserializeFromString
。
次のコードがあります。
async public static void TryLoad(Action<JsonArrayObjects> Ok,
Action<string> Fail, string key, int offset)
{
try
{
var folder = ApplicationData.Current.LocalFolder;
var stream = await folder.OpenStreamForReadAsync(key);
var result = await new StreamReader(stream).ReadToEndAsync();
Debug.WriteLine(result);
var cacheItem = TypeSerializer.DeserializeFromString<CacheItem>(result);
if (cacheItem.IsValid(offset) == true) Ok(cacheItem.Data); else Fail(key);
}
catch (Exception)
{
Fail(key);
}
}
Debug.WriteLine
ここでは正しい JSON 文字列を出力しますが、次の行でTypeSerializer.DeserializeFromString
例外が発生します。
A first chance exception of type 'System.IndexOutOfRangeException' occurred in Unknown Module.
TypeSerializer
空の文字列を取得するようです。なぜそれが起こっているのですか、どうすれば修正できますか?