This article is using jquery Ajax call WebService to return the JSON array Oh, JSON data is a small lightweight data for web effects, and real-time interactivity is stronger than XML.
JSON data
{' Employee ': [{' Name ': ' John ', ' Sex ': ' Man ', ' age ': '},{' ' name ': ' Tom ', ' Sex ': ' Mans ', ' age ': '},{' name ': ' Mary ', ' Sex ': ' Woman ', ' Age ': '}
'}
jquery calls WebService import data
function LoadData () {
var studentdata = Collectiondata ();
$.ajax ({
URL: "Importdataservice.asmx/importstu",
Type: "Post",
ContentType: "Application/json;charset=utf-8",
DataType: "JSON",
Data: "{' Students ': [{' name ': ' Kobe ', ' sex ': ' Boy ', ' age ': '},{' name ': ' Mary ', ' Sex ': ' Girl ', ' age ': ' 19 '}]} ',
Success:function (Result) {
alert (RESULT.D);
},
Error:function (e) {
alert (E.responsetext);
}
});
}
<summary>
///
</summary>
<param name= "Students" ></param>
<returns></returns>
[WebMethod]
[Scriptmethod (Responseformat=responseformat.json)]
public string Importstu (dictionary<string,string> []students)
{
if (students.length = 0)
{
Return "No data!"
}
Else
{
Try
{
foreach (dictionary<string, string> stu in students)
{
Constructs a new student object.
Student student = new Student ();
Assigns a value to the newly constructed student object property.
foreach (string key in Stu.keys)
{
Switch (key)
{
Case "Name":
Student.name = Stu[key];
Break
Case "Sex":
Student.sex = Stu[key];
Break
Case "Age":
int age;
if (Int32.TryParse (Stu[key], out of age)
{
Student.age = age;
}
Else
{
student.age = 0;
}
Break
Default
Break
}
}
}
Return "Import Student success!"
}
Catch
{
Throw new Exception ("Failed to import student!");
}
}
}