【发布时间】:2016-12-19 01:32:25
【问题描述】:
我目前正在使用Newtonsoft.json nuget 包,但我想找到一个更快的替代方案。 ServiceStack.Text 似乎可以解析它,但它以我期望的不同格式返回 JSON。无论如何要更改返回对象的格式以匹配我的期望吗?
问题是在反序列化后,response.fullName 会返回 Newtonsoft.json 预期的“joey cool”,但 ServiceStack.Text 将返回 null,因为格式不同。
我可以更改ServiceStack.Text 的输出格式以使其符合我的预期吗?我想打电话给response.fullName 并得到“乔伊酷”。
这是我使用 ServiceStack.Text 组件的代码:
T response = a_response.Content.FromJson<T>();
这是我使用 Newtonsoft.json 的代码:
T response = JsonConvert.DeserializeObject<T>(a_response.Content);
以下是文本中的 JSON 作为输出的样子:
{ "userId": "fc7b4c4e0b6660c7daf711b1d17e0039", "emailAddress": "joey+100@stringify.com", "fullName": "乔伊酷", "accountType": "个人", “创建日期”:1440104822411, "电话号码": "15555555555", "timezone": "America/Los_Angeles", "照片": "https://stringify.s3.amazonaws.com/users/fc7b4c4e0b6660c7daf711b1d17e0039-profile.jpg", “名称”:“默认”, “类型”:“API” }
下面是您的ServiceStack.Text JSON Deserializer 如何显示响应对象:
----编辑---- 从 NuGet 尝试了 4.0.62,它给了我一个例外。
消息:“ServiceStack.StringExtensions”的类型初始化程序引发了异常。对象引用未设置为对象实例,位于 ServiceStack.StringExtensions..cctor () [0x00017] in :0
-----编辑-----
URL to a file containing the JSON class
Here's a video demonstrating the usage differences and the strange output
【问题讨论】:
标签: c# .net json xamarin servicestack-text