Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解析值数组-jQuery_Jquery_Asp.net - Fatal编程技术网

解析值数组-jQuery

解析值数组-jQuery,jquery,asp.net,Jquery,Asp.net,我从jQuery调用一个Web服务来获取员工和学生的详细信息。在我的web服务中,我为员工和学生提供了值,并将这些值作为字符串数组返回。在返回值时,我只是将这两个值序列化为 [WebMethod(EnableSession = true)] public string[] fetchStudentStaff(string sectionId) { string student; string staff; //// //// student = jsonSerialize.Serialize(s

我从jQuery调用一个Web服务来获取
员工
学生
的详细信息。在我的web服务中,我为员工和学生提供了值,并将这些值作为字符串数组返回。在返回值时,我只是将这两个值序列化为

[WebMethod(EnableSession = true)]
public string[] fetchStudentStaff(string sectionId)
{
string student;
string staff;
////
////
student = jsonSerialize.Serialize(studentList);
staff = jsonSerialize.Serialize(staffList);

return new string[] { student, staff };
}
这里有一个名为
category
的变量,用于说明他是教职员工还是学生。在我的jQuery部分,我作为

    [
    [
        [
            {
                "Name": "shanish",
                "StudentId": "12",
                "Category": "Student",
                "Mobile": "8147708287",
                "Email": "shanish@gmail.com"
            }
        ]
    ],
    [
        [
            {
                "Name": "shanish",
                "StaffId": "78",
                "Category": "Staff",
                "Mobile": "8147708287",
                "Email": "shanish@gmail.com"
            }
        ]
    ]
]
在这里,我尝试使用
jQuery.parseJSON(data.d)
对结果进行分组,但结果是
null
,我需要使用
student
staff
对结果进行分类,这里我有一个学生和一个教职员工,对于5个学生和2个教职员工的情况,我需要在一个单独的变量中存储学生,在一个单独的变量中存储两个职员


我不知道如何做到这一点,这里有人能帮我吗…提前谢谢

我将发送一条结构化消息:

return jsonSerialize.Serialize(new {students=studentList, staff=staffList});
然后在客户机上:

$.ajax({url: urlToFetchStudentStaff, data: sectionId, dataType: 'json',
        success: function(result) {
            // assuming result.d is the JSON result message
            alert(result.d.students.length); // d.students is an array of students
            alert(result.d.staff.length); // d.staff is an array of staff
        });

那么我如何在jquerycan u try alert(result)中进行分类呢。它将打印JSON数据。你能看到它吗?看看我更新的答案。如果您指定
dataType:json
,jQuery应该自动将生成的消息解析为json,这样您就可以直接使用它了。@HackedByChinese:谢谢你,伙计,我希望你的解决方案真的能帮助我,我会尝试一下,让你know@VeeKeyBee:警报框不显示确切结果,它将结果显示为[对象],[对象]…像这样,就足够了,我可以用这个来实现,谢谢你的支持