将JSON数组从c#传递给jQuery

Mr.*_*. D 3 c# jquery json jquery-autocomplete

我正在做jQuery自动完成.如果我把硬编码的JSON数组放入工作正常.但是当我从c#传递数组时它失败了.请帮助,我花了足够的时间与它,我被卡住了!

这是我在AutoComplete.aspx中的jQuery代码

<script type="text/javascript">
    $(document).ready(function () {
        var msgbox = $("#status");
        $.ajax({
            type: "POST",

            //Page Name (in which the method should be called) and method name
            url: "AutoControl.aspx/GetData",

            //else If you don't want to pass any value to server side function leave the data to blank line below
            data: "{}",

            contentType: "application/json; charset=utf-8",
            dataType: "json",

            success: function (msg) {
                $("#status").val(msg.d);
            }
        });

        $('#<%=tags.ClientID%>').autocomplete(["c++", "java", "php", "coldfusion"], {
            width: 320,
            max: 4,
            highlight: false,
            multiple: true,
            multipleSeparator: " ",
            scroll: true,
            scrollHeight: 300
        });
    });        

</script>
Run Code Online (Sandbox Code Playgroud)

这是我在AutoComplete.aspx.cs中的C#代码

[System.Web.Services.WebMethod]
    public static string GetData()
    {
        return "\"c++\", \"java\", \"php\"";
    }
Run Code Online (Sandbox Code Playgroud)

如何将JSON数组从C#传递给jQuery.使用此代码,我可以从c#中检索值,但有些原因JSON没有读取值.

我想更改此代码:$('#<%= tags.ClientID%>').autocomplete(["c ++","java","php","coldfusion"]

$('#<%= tags.ClientID%>').autocomplete([ jsonArray_from_C# ]

Gab*_*ães 5

你试过返回一个字符串数组吗?

http://encosia.com/2011/04/13/asp-net-web-services-mistake-manual-json-serialization/

不要尝试解析Json,直接传递对象.