JSON.Net VB 反序列化不起作用
我是 VB 新手,正在尝试编写一个导出和导入 JSON 的 Web 服务。
我正在使用 JSON.NET 3.5 并且可以很好地序列化:
我的 Token 类是:(
<DataContract()> _
Public Class Token
<DataMember()> _
Public TokenID As String
<DataMember()> _
Public Issued As Date
<DataMember()> _
Public Expires As Date
<DataMember()> _
Public UserName As String
<DataMember()> _
Public CompanyID As String
<DataMember()> _
Public ApplicationID As Double
<DataMember()> _
Public UserID As Double
<DataMember()> _
Public DeviceID As Double
<DataMember()> _
Public DeviceSerialNumber As String
<DataMember()> _
Public IsValid As Boolean
<DataMember()> _
Public DebugText As String
我从 MS 的序列化开始,但我想我会尝试 JSON.NET)
我序列化为:
Dim ThisToken as New Token ThisToken.DebugText =“废话” 等等
JSONString = Newtonsoft.Json.JsonConvert.SerializeObject(ThisToken)
我从网络服务中得到以下输出:
{"TokenID":"9eaae348-5cbd-46ac-8ba9-83720ac07740","Issued":"/Date(1300422761886+0800)/","Expires":"/日期(1300465961886+0800)/","用户名":"1234","公司ID":"6","应用程序ID":1.0,"用户ID":29.0,"设备ID":1.0,"设备序列号":"9149520800758" ,"IsValid":true,"DebugText":""}
到目前为止,我认为一切都很好。
为了测试反序列化是否有效,我想我应该尝试反序列化我刚刚序列化的内容。因此,我创建了一个接受字符串的 Web 服务,并将以上内容粘贴到其中。
反序列化的代码是:
Dim ThisToken As New Token
ThisToken = Newtonsoft.Json.JsonConvert.DeserializeObject(JSonString)
当我使用 VS2005 内部调试/IE 测试运行代码时,我收到 http500 内部服务器错误。
如果我尝试在序列化后立即反序列化,我也会遇到同样的问题。
我认为部分问题在于我遵循的代码是 c#;从 json.net 页面:
Product deserializedProduct = JsonConvert.DeserializeObject<Product>(json);
我可以看到,在 c# 中,有一个
部分,在 vb 中不容易出现?
我毫不怀疑 newtonsoft json.net 产品运行良好;我确信我没有做正确的事情。
帮助 ?
安德鲁
I'm new to VB and trying to write a webservice that exports and imports JSON.
I'm using JSON.NET 3.5 and can serialize fine:
My Token class is:
<DataContract()> _
Public Class Token
<DataMember()> _
Public TokenID As String
<DataMember()> _
Public Issued As Date
<DataMember()> _
Public Expires As Date
<DataMember()> _
Public UserName As String
<DataMember()> _
Public CompanyID As String
<DataMember()> _
Public ApplicationID As Double
<DataMember()> _
Public UserID As Double
<DataMember()> _
Public DeviceID As Double
<DataMember()> _
Public DeviceSerialNumber As String
<DataMember()> _
Public IsValid As Boolean
<DataMember()> _
Public DebugText As String
(I started with MS's serialization but thought i'd try JSON.NET)
I serialize with:
Dim ThisToken as New Token
ThisToken.DebugText = "blah"
and so on
JSONString = Newtonsoft.Json.JsonConvert.SerializeObject(ThisToken)
And I get this output from the webservice:
{"TokenID":"9eaae348-5cbd-46ac-8ba9-83720ac07740","Issued":"/Date(1300422761886+0800)/","Expires":"/Date(1300465961886+0800)/","UserName":"1234","CompanyID":"6","ApplicationID":1.0,"UserID":29.0,"DeviceID":1.0,"DeviceSerialNumber":"9149520800758","IsValid":true,"DebugText":""}
So far so good I think.
To test that deserialization is working, I thought i'd try and deserialise what I just serialised. So I create a webservice that accepts a string and I paste the above into it.
code to deseralise is:
Dim ThisToken As New Token
ThisToken = Newtonsoft.Json.JsonConvert.DeserializeObject(JSonString)
When I run the code using VS2005 internal debug/IE testing, I get an http500 internal server error.
I also get the same problem if I try to deserialize immediately after serializing.
I think part of the problem is that the code I was following was c#; from the json.net page:
Product deserializedProduct = JsonConvert.DeserializeObject<Product>(json);
I can see that in c# there is a <Product>
part which is not readily apparant in vb ?
I have no doubt that the newtonsoft json.net product works fine; I'm sure that i'm not doing something right.
Help ?
Andrew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
VB 相当于
is
所以我想你想要
The VB equivalent to
is
So I think you want