我得到了Json的反应:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">{"records":"830","page":1,"total":42,"rows":[{"Guid":"0565bbfe-3533-42ee-b935-4cf491399994","group_name":"Chart Of The Week","Name":"UK house prices and GDP","ChartOwner":"ADMIN","pathname":"Datastream\\Charts from Alpha Now\\Chart Of The Week\\|-3,45571,100060,"},{"Guid":"65fea74c-0125-46b2-a618-6cf5b7abf162","group_name":"Residential Sector","Name":"Weekly Residential GFA Sold in Guiyang","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"21f8c6dd-3437-4517-a532-457c09c1d80f","group_name":"Residential Sector","Name":"Weekly Residential GFA Sold in Shaoguan","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"45c82732-54a0-4e93-bb07-30099a07fe3f","group_name":"Residential Sector","Name":"Weekly Residential GFA Sold in Shaoxin","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"074731f2-7578-457c-89e9-14a3b09b67c3","group_name":"Residential Sector","Name":"Weekly Residential GFA Sold in Shenyang","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"c287c938-4f87-4319-a1ed-a015d1690742","group_name":"Residential Sector","Name":"Weekly Residential GFA Sold in Suzhou","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"10a1af78-32d8-4306-bff2-1d44ea8a6b0e","group_name":"Residential Sector","Name":"Weekly Residential GFA Sold in Tianjin","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"4fe34cd4-cf3d-4343-9de3-9b1467f73025","group_name":"Residential Sector","Name":"Weekly Residential GFA Sold in Wenzhou","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"b5afa485-1bac-4cd3-8ebc-54d1eb82b9f0","group_name":"Residential Sector","Name":"Weekly Residential GFA Sold in Wuhan","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"63d560e8-2f8f-436d-b150-a4b35b404452","group_name":"Residential Sector","Name":"Weekly Residential GFA Sold in Xiamen","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"87b51f8e-0b8b-488b-8fa7-8dad1a6d60d3","group_name":"Residential Sector","Name":"Weekly Residential GFA Sold in Xi'an","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"0b8904cf-948f-43c9-ad10-53eb5334b41d","group_name":"Residential Sector","Name":"Weekly Residential GFA Sold in Wuxi","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"795b7370-36c8-47cf-a682-2d5118898a60","group_name":"Residential Sector","Name":"Average House Price in Beijing and Y/Y Change","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"d35706ec-71be-4551-8073-0aed4a02da52","group_name":"Residential Sector","Name":"Average House Price in Chongqing and Y/Y Change","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"5d6414c6-c3c5-4343-9e5d-35359849d28e","group_name":"Residential Sector","Name":"Average House Price in Guangzhou and Y/Y Change","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"67f6b3f8-1b74-4292-8a5f-fb41529e2640","group_name":"Residential Sector","Name":"Average House Price in Hangzhou and Y/Y Change","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"0f229364-e553-4aa9-954d-deee7796a578","group_name":"Residential Sector","Name":"Average House Price in Nanjing and Y/Y Change","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"bb6abe38-2ac1-442b-a718-c0ab199e7bc2","group_name":"Residential Sector","Name":"Average House Price in Shanghai and Y/Y Change","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"0a195ca1-e1fe-4a4a-939e-792cf979d4bb","group_name":"Residential Sector","Name":"Average House Price in Shenzhen and Y/Y Change","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"},{"Guid":"ee6ee3a9-0306-4611-b700-1cd74870bb72","group_name":"Residential Sector","Name":"Average House Price in Xiamen and Y/Y Change","ChartOwner":"ADMIN","pathname":"Datastream\\Real Estate Markets\\_Real Estate Foresight\\Residential Sector\\|-3,58585,97205,100070,"}]}</string>
而且,我的jqGrid代码如下所示:
$(document).ready(function () {
$("#jqGrid").jqGrid({
url: 'LibraryWebService.asmx/GetCharts',
mtype: "POST",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
colModel: [
{ label: 'Guid', name: 'Guid', key: true, width: 75 },
{ label: 'group_name', name: 'group_name', width: 100 },
{ label: 'Name', name: 'Name', width: 150 },
{ label: 'ChartOwner', name: 'ChartOwner', width: 75 },
{ label: 'pathname', name: 'pathname', width: 250 }
],
page: 1,
width: 780,
height: 250,
rowNum: 20,
multiselect: true,
scrollPopUp: true,
scrollLeftOffset: "83%",
viewrecords: true,
gridview: true,
loadonce: true,
scroll: 1, // set the scroll property to 1 to enable paging with scrollbar - virtual loading of records
emptyrecords: 'Scroll to bottom to retrieve new page', // the message will be displayed at the bottom
pager: "#jqGridPager"
});
$("#getselected").click(function () {
var sr = $("#jqGrid").jqGrid('getGridParam', 'selarrrow');
if (sr.length) {
alert(sr.join());
} else {
alert("no charts are selected!");
}
});
});
网格未显示。 当我删除scroll = 1属性时,我看到空网格和寻呼机为:第1页,共0页。
答案 0 :(得分:0)
人们可以看到&#34;响应Json&#34;是XML而没有JSON。您应该更改代码的服务器部分以不返回XML包装器。
另外要了解ASMX方法应该返回object
而不是string
,这一点非常重要。您不需要将对象手动转换为JSON字符串。转换根据请求的Accept
HTTP标头中的信息自动为您执行XML或JSON。
此外,您应该替换不存在的选项 dataType: 'json'
和contentType: 'application/json; charset=utf-8' to
数据类型:&#39; json&#39; and
ajaxGridOptions:{contentType: &#39;应用/ JSON;字符集= UTF-8&#39;}`
我建议您删除scroll: 1
选项并使用标准分页。
如果您使用loadonce: true
选项,则可以跳过服务器响应中的"records":"830","page":1,"total":42,"rows"
部分。您可以将所有 830记录作为项目数组(当前响应中rows
属性的值)返回。