如何使用Javascript在客户端使用WebMethod返回的复杂类型?

如何使用Javascript在客户端使用WebMethod返回的复杂类型?,javascript,jquery,.net,ajax,web-services,Javascript,Jquery,.net,Ajax,Web Services,我是Webmethods和服务的初学者,我在这里遇到了一种情况 我有一个webmethod,它返回StatusViewModel类的实例 [WebMethod()] public static StatusViewModel GetTime1() { Debug.Write("Timer"); StatusViewModel statusViewModel = new StatusViewModel(); statusVi

我是Webmethods和服务的初学者,我在这里遇到了一种情况

我有一个webmethod,它返回StatusViewModel类的实例

    [WebMethod()]
    public static StatusViewModel GetTime1()
    {
        Debug.Write("Timer");

        StatusViewModel statusViewModel = new StatusViewModel();
        statusViewModel.Label1 = "aaa";
        statusViewModel.Label1 = "bbb";

        statusViewModel.ListBox.Add("1", "ccc");
        statusViewModel.ListBox.Add("2", "ccc");

        return DateTime.Now.ToString();

    }
StatusViewModel类与此类似

public class StatusViewModel
    {
        public string Label1 { get; set; }
        public string Label2 { get; set; }
        public IDictionary<string, string> ListBox { get; set; }
    }
公共类状态视图模型
{
公共字符串Label1{get;set;}
公共字符串Label2{get;set;}
公共IDictionary列表框{get;set;}
}
我应该如何使用此方法并使用从该方法接收的数据设置2个标签和列表框

通常这就是我称之为webmethod的方式

 $(document).ready(function() {
            call1();
        });


        function OnSuccess1(result, ctrl) { $('#<%=Label2.ClientID %>').html(result); }
        function OnError1() { alert("error!"); }
        function call1() { PageMethods.GetTime1(OnSuccess1, OnError1); }
$(文档).ready(函数(){
call1();
});
函数OnSuccess1(result,ctrl){$('#').html(result);}
函数OnError1(){alert(“error!”;}
函数call1(){PageMethods.GetTime1(OnSuccess1,OnError1);}
如果返回类型为String,则此操作有效


有人能推荐一些关于这个主题的简单文章吗?

尝试将类转换为JSON。然后你就可以在javascript中轻松地阅读它了,这是一个不错的开始


它给你信息,休息-只要谷歌和尝试自己的东西。这是一项简单而普通的任务。

@Fender..+1.谢谢。。你能推荐一些关于如何做到这一点的文章吗?不好的建议,你永远不应该手工做,因为你不知道这是由框架完成的,从来没有过这种情况。每当我使用JavaScriptSerializer时,我不必做双重JSON.parse。。。