Javascript JSON客户端

Javascript JSON客户端,javascript,jquery,json,Javascript,Jquery,Json,以下代码块运行时没有错误,但“数据”返回为单个一维记录。代码返回一条记录,其中包含所有记录,即,如果我调试并将“data”变量输出到即时窗口,我会得到: ?data {...} [0]: "127" [1]: "Barnesmore" [2]: "-7.934532" [3]: "54.692091" [4]: "75" [5]: "Beinn an Tuirc" [6]: "-5.583115" [7]: "55.565631"

以下代码块运行时没有错误,但“数据”返回为单个一维记录。代码返回一条记录,其中包含所有记录,即,如果我调试并将“data”变量输出到即时窗口,我会得到:

?data
{...}
    [0]: "127"
    [1]: "Barnesmore"
    [2]: "-7.934532"
    [3]: "54.692091"
    [4]: "75"
    [5]: "Beinn an Tuirc"
    [6]: "-5.583115"
    [7]: "55.565631"
    [8]: "78"
    [9]: "Beinn Tharsuinn"
    [10]: "-4.251795"
    [11]: "57.805856"
    [12]: "77"
    [13]: "Black Law"
    [14]: "-3.705482"
    [15]: "55.77749"
    [16]: "1"
    [17]: "BlackLaw Phase 3"
    [18]: "323232"
    [19]: "121212"
    20: null
    21: null
    22: null
    23: null
    length: 24
但是元素[0]到[3]是记录,[4]到[7]是记录,依此类推。如何更改代码以循环记录?非常感谢阅读,下面是我的代码片段:

        var index = 0;
        var itemData;
        var url = $("#AbsolutePath").val() + "Site.mvc/GetMapList/" + "?siteDescription=" + $('#SearchTextBox').val();

        var arr = $.getJSON(url, null, function(data) {

            $.each(data, function(index, itemData) {
                debugger;
                alert(itemData);

            });

        });
控制器代码:

    public JsonResult GetMapList(string siteDescription)
    {
        var allSites = _siteRepository.FindAllSites();
        //Get all Sites that contain the value in sitedescription
        var searchResults = (from s in allSites
                             where s.SiteDescription.StartsWith(siteDescription)
                             select s);

        // We need an object client side to loop through in Javascript and add all the tags to the Map for each site in Search Results
        string[,] sArray = new string[searchResults.Count(), 4];
        int i = 0;

        foreach (Site item in searchResults)
        {
            if (item.SiteLocation == null || item.SiteLocation.SiteLocationId == 0)
            { }
            else
            {
                if ((item.SiteLocation.Latitude != 0) && (item.SiteLocation.Longitude != 0))
                {

                    sArray[i, 0] = item.SiteId.ToString();
                    sArray[i, 1] = item.SiteDescription.ToString();
                    sArray[i, 2] = item.SiteLocation.Longitude.ToString();
                    sArray[i, 3] = item.SiteLocation.Latitude.ToString();
                    i++;
                }
            }
        }
        return this.Json(sArray);
    }

??关于

for(i=0; i < data.length; i + 4 ){
  var myrecord = "Record Number: " + data[i] + ", Place: " +  data[i + 1] + ", Longitude: " + data[i + 2] + ", Latitude: " + data[i + 3];
  alert (myrecord);
}
for(i=0;i
?关于

for(i=0; i < data.length; i + 4 ){
  var myrecord = "Record Number: " + data[i] + ", Place: " +  data[i + 1] + ", Longitude: " + data[i + 2] + ", Latitude: " + data[i + 3];
  alert (myrecord);
}
for(i=0;i
如果可能,您应该更改所获取数据的结构。是你自己创造的吗?如果是,请显示代码。看起来数据是一个对象,而不是列表/数组。我们需要了解您是如何在服务器上生成数据的。如果可能,您应该更改所获取数据的结构。是你自己创造的吗?如果是,请显示代码。看起来数据是一个对象,而不是列表/数组。我们需要看看你是如何在服务器上生成数据的。我知道我可以用一个循环等来伪造数据,但我希望它更整洁,我已经在上面发布了控制器代码。让它与上面的代码类似的循环一起工作,让allAnyone知道如何将JSON结果作为记录集合打开,这是一个混乱的解决方案,我已经got@John:您应该在文档中查找您正在使用的语言,以获得JSON中的对象。我知道我可以使用循环等来伪造它,但希望它更整洁,我已经发布了上面的控制器代码。让它同时与上面的代码类似的循环一起工作,欢呼allAnyone知道如何将JSON结果作为记录集合打开,这是一个混乱的解决方案got@John:您应该在文档中查找您正在使用的语言,以便在JSON中拥有对象。