获得使用webmeothd JSON对象的值在vb.net [英] Getting Values of a JSON Object using webmeothd in vb.net
问题描述
同时获得在vb.net JSON对象的价值我被困。我的JSON请求的帖子,如数据如下:
I got stuck while getting value of a JSON object in vb.net. My JSON request posts data like given below:
function submitEmail() {
var ClientsPersonalInfo = {
FullName: $("#FullName").val(),
PhoneNumber: $("#PhoneNumber").val(),
EmailAddress: $("#EmailAddress").val(),
DOB: $("#DOB").val(),
Occupation: $("#Occupation").val(),
NINumber: $("#NINumber").val(),
FullAddress: $("#FullAddress").val()
}
var ClientsData = {};
ClientsData.ClientsPersonalInfo = ClientsPersonalInfo;
var d = '{"ClientsData":' + JSON.stringify(ClientsData) + '}'
$.ajax({
type: "POST",
url: "add-new-client.aspx/SubmitEmail", // WebMethod Call
data: d,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response)
},
failure: function (msg) {
alert(msg);
}
});
}
JSON对象看起来像
{
"ClientsPersonalInfo": {
"FullName": "",
"PhoneNumber": "",
"EmailAddress": "",
"DOB": "",
"Occupation": "",
"NINumber": "",
"FullAddress": ""
}
}
以上请求将返回vb.net对象
The above request returns an object in vb.net
VB code:
<WebMethod()> _
Public Shared Function SubmitEmail(ByVal ClientsPersonalInfo As Object) As String
'What to do next to get object "ClientsPersonalInfo"
'I want to access properties of the object like
'Dim name As String = ClientsPersonalInfo.FullName
Return "Successfully Converted."
End Function
没有我想要得到这个对象的值,需要在表中追加。请指导我如何获得上述目的的价值?我是新的vb.net。请指导。谢谢!
No I want to get values of this object and needs to append in a table. Please guide me how to get values of the above object? I am new in vb.net. Please guide. Thanks!
推荐答案
首先,你需要添加 ClientsData code>和
ClientsPersonalInfo
类Web服务:
First, you need to add the ClientsData
and ClientsPersonalInfo
classes to your web service:
Public Class ClientsPersonalInfo
Public Property FullName As String
Public Property PhoneNumber As String
Public Property EmailAddress As String
Public Property DOB As String
Public Property Occupation As String
Public Property NINumber As String
Public Property FullAddress As String
End Class
Public Class RootObject
Public Property ClientsPersonalInfo As ClientsPersonalInfo
End Class
现在,你可以简单地改变参数类型在Web服务方法和.Net引擎将要解析为您提供:
Now, you can simply change the parameter type in your web service method and .Net engine will do the parsing for you:
<WebMethod()> _
Public Shared Function SubmitEmail(ByVal MyClientsPersonalInfo As ClientsPersonalInfo) As String
'You can access properties of the object like
Dim name As String = MyClientsPersonalInfo.FullName
Return "Successfully Converted."
End Function
这篇关于获得使用webmeothd JSON对象的值在vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!