weixin_33712987 2011-03-24 23:46 采纳率: 0%
浏览 28

解析出ajax json结果

I'm trying to parse out some data thats returned from a web service via json with the following code.

        function getADData() {
        var strSearch = $('#txtSearch').val()
        var ajaxData = "{ 'PartNameString': '" + strSearch + "' }";
        $.ajax({
            type: "POST",
            url: "/Services/ActiveDirectoryInterop.asmx/SearchUsers",        
            data: ajaxData,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success:populateTable
        });
    }

    function populateTable(result) {
        alert(result["d"].length);
    }

Data Returned is this.

{"d":{"Columns":["UserID","Name","Email"],"Rows":[["U99999","Lees, Smith","someemail1@canfor.com"],["U99999","Lees, Mark","someemail1@canforpulp.com"],["99999","Lees, Bob","someemail1@canforpulp.com"],["U999999","Lees, John","someemail1@canforpulp.com"],["U999999","Lees, Jim","someemail1@canforpulp.com"]]}}

What the alert though jsut returns undefined. So i know I'm missing something and it probably has to do with the nesting of the JSON. Can someone point me in the right direciton for some materials or code that shows me how to possibly traverse data like what i'm recieving.

  • 写回答

3条回答 默认 最新

  • weixin_33717298 2011-03-24 23:49
    关注

    Try this instead:

    alert(result.d.Columns.length);
    

    And read up on that weirdo 'd'.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!