我正在尝试序列化 JSON 对象,以便将其发送到 Web 服务。我正在使用这个 asp.net vb 代码:
Dim ser As DataContractJsonSerializer = New DataContractJsonSerializer(postData.GetType())
Dim MS As MemoryStream = New MemoryStream()
ser.WriteObject(MS, postData)
json = Encoding.UTF8.GetString(MS.ToArray())
产生这个 JSON:
{"guid":"10049cf5-a622-4aa6-a1d5-58022c4e2a19"}
但我需要的是……这个 JSON:
{"registerRequest": {"guid":"10049cf5-a622-4aa6-a1d5-58022c4e2a19"}}
这是我要发送的对象的类定义:
Partial Public Class registerRequest
Private Property _guid As String
Public Property guid As String
Get
Return _guid
End Get
Set(value As String)
_guid = value
End Set
End Property
Sub New()
End Sub
End Class
如上所述,如何让类的名称出现在 JSON 对象中?