C# 如何将JSON数据绑定到Kendo网格

C# 如何将JSON数据绑定到Kendo网格,c#,json,wcf,kendo-ui,kendo-grid,C#,Json,Wcf,Kendo Ui,Kendo Grid,我使用我的WCF服务公开JSON数据: [OperationContract] [WebGet(ResponseFormat=WebMessageFormat.Json)] List<ProductDetails> GetProductDetails(); [运营合同] [WebGet(ResponseFormat=WebMessageFormat.Json)] 列出GetProductDetails(); 以下是返回的JSON示例: {“d”:[{“uuu类型”:“Pro

我使用我的WCF服务公开JSON数据:

 [OperationContract]
 [WebGet(ResponseFormat=WebMessageFormat.Json)]
 List<ProductDetails> GetProductDetails();
[运营合同]
[WebGet(ResponseFormat=WebMessageFormat.Json)]
列出GetProductDetails();
以下是返回的JSON示例:

{“d”:[{“uuu类型”:“ProductDetails:#NWProducts”,“折扣”:0,“OrderId”:10248,“ProductId”:11,“单价”:14.0000,“数量”:12},{“uuu类型”:“ProductDetails:#NWProducts”,“折扣”:0,“OrderId”:10248,“ProductId”:42,“单价”:9.8000,“数量”:10},{“uuu类型”:“ProductDetails:#NWProducts”,“折扣”:0,“OrderId”:10248,“ProductId”:72,“单价”:34.8000,“数量”:5},{uuuu类型”:“产品详细信息:{NWProducts”,“折扣”:0,“订单ID”:10249,“产品ID”:14,“单价”:18.6000,“数量”:9},{uuuuu类型”:“产品详细信息:{NWProducts”,“折扣”:0,“订单ID”:10249,“产品ID”:51,“单价”:42.4000,“数量”:40}

尝试使用以下方法将其绑定到剑道网格:

   <script>
                $(document).ready(function () {
                    $("#grid").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: "http://localhost/KendoServices/Web/GetProductDetails"
                            },
                            pageSize: 10
                        },
                        groupable: true,
                        sortable: true,
                        pageable: {
                            refresh: true,
                            pageSizes: true,
                            buttonCount: 5
                        },
                        columns: [{
                            field: "OrderId",
                            title: "OrderId",
                            width: 140
                        }, {
                            field: "ProductId",
                            title: "ProductId",
                            width: 190
                        }, {
                            field: "UnitPrice",
                            title: "UnitPrice"
                        }, {
                            field: "quanity",
                            width: 110
                        }]
                    });
                });
            </script>

$(文档).ready(函数(){
$(“#网格”).kendoGrid({
数据源:{
键入:“json”,
运输:{
阅读:“http://localhost/KendoServices/Web/GetProductDetails"
},
页面大小:10
},
分组:对,
可排序:是的,
可分页:{
刷新:是的,
页面大小:对,
按钮数:5
},
栏目:[{
字段:“订单ID”,
标题:“订单ID”,
宽度:140
}, {
字段:“产品ID”,
标题:“产品ID”,
宽度:190
}, {
字段:“单价”,
标题:“单价”
}, {
字段:“数量”,
宽度:110
}]
});
});

由于某些原因,我无法在网格上看到任何数据。我尝试绑定数据的方式可能有问题。

这里的罪魁祸首是生成的JSON。默认情况下,剑道数据源会在名为results的数组中查找返回对象的项。修复起来很简单。只需定义数据在respon中的位置se JSON对象

dataSource: {
    transport: {
        read: {
             url: "http://localhost/KendoServices/Web/GetProductDetails",
             dataType: 'json'
        }
    },
    pageSize: 10,
    schema: {
        data: function(response) {
            return response.d;
        }
    }
},
--编辑。。。 哎哟,还漏了点什么。你的
类型:“json”
应该在你的read对象中,并且应该是
数据类型:“json”
试试这个

dataSource: {
    transport: {
            read: {
                   url: "http://localhost/KendoServices/Web/GetProductDetails",
                   contentType: 'application/json; charset=utf-8',
                   dataType: "json"
                  }
    },
    schema: {
                 data: "d"
            }
    }
}

我就是这样做的:

    $("#grid").kendoGrid({
        dataSource: {               
            transport: {
                    read: { 
                            url : pUrl,
                            dataType: "json"
                    }
            },
            pageSize:40,                
            schema: {
                data: function(response) {
                    return response.json;
                }
            }               

        },
        height: 550,
        groupable: false,
        sortable: true,
        pageable: {
            refresh: false,
            pageSizes: false,
            buttonCount: 5
        },
        columns: [
            {
                field: "SEQ_NO",
                title: "No",
                filterable: false,
                width: 120
            }, {
                field: "LOT_NO",
                title: "Lot No (INS' No)"
            }, {
                field: "TYPE",
                title: "INPUT (At 100% Burden)"
            }, {
                field: "ATTRIBUTE01",
                title: "1.0 In"
            }, {
                field: "ATTRIBUTE02",
                title: "2.0 In"
            }, {
                field: "ATTRIBUTE03",
                title: "0.05 In"
            }, {
                   field: "RESILT",
                   title: "RESILT"
            }
        ]
    });

只是一个提议…尝试添加
服务器操作:false
仍然相同,如果您停止返回响应,则无法在网格上看到任何数据。d检查响应对象,它是否在某个位置包含所有JSON?无法在响应处获得断点。d但可以签入Fiddler我正在获取JSON中的所有内容你的意思是内部传输对象,如果需要内部读取,你能用代码更新答案吗?对不起,我今天早上不玩游戏了。修复了transport.read,它应该是一个具有url和数据类型属性的对象。不鼓励指向图像的外部链接。