我需要在我的 MonoTouch iPhone 应用程序中支持 UTF-8,并且刚刚更新了我所有的服务器 PHP 脚本以使用 UTF-8 而不是 ANSI 进行编码。
此更改破坏了我的客户端代码,并且在尝试序列化从 PHP 脚本返回的字符串时在 ServiceStack 中抛出异常。
using (StreamReader reader = new StreamReader (webResponse.GetResponseStream (), Encoding.UTF8))
{
string responseString = reader.ReadToEnd();
myDto = JsonSerializer.DeserializeFromString (responseString, dtoType);
}
Exception: System.Runtime.Serialization.SerializationException: Type definitions should start with a '{', expecting serialized type 'UserGamesDTO', got string starting with: {"uc":"0","gma":[{"gid":"838","ui
异常是提示字符串不是以“{”开头,而它显然是以“{”开头,那么这是否意味着 ServiceStack 不能使用 UTF-8 字符串,或者我需要设置一些东西吗?
谢谢。
最佳答案
您是否考虑过字节顺序标记 (BOM) 字符,这是文本编辑器中不显示的 Unicode 字符。 也许你应该摆脱它。
关于php - ServiceStack JsonSerializer.DeserializeFromString 不适用于 UTF-8 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18171531/