Javascript 如何将此JSON发送到jqGrid?

Javascript 如何将此JSON发送到jqGrid?,javascript,jquery,json,jqgrid,Javascript,Jquery,Json,Jqgrid,我无法从无法访问的服务器读取此类JSON,因此无法操作JSON: { “API_ICDFactory”:{ “API_getDataSample”:{ “密钥0”:{ “dateTransaction”:“1379454296”, “日期账单”:“1387320296”, “单位”:“181”, “价格单位”:“25.12”, “金额”:“4546.72”, “公司”:“Juan Vivas Higher”, “productRef”:“CAR”, “产品说明”:“洗涤剂特别是抗静电剂” },

我无法从无法访问的服务器读取此类JSON,因此无法操作JSON:

{
“API_ICDFactory”:{
“API_getDataSample”:{
“密钥0”:{
“dateTransaction”:“1379454296”,
“日期账单”:“1387320296”,
“单位”:“181”,
“价格单位”:“25.12”,
“金额”:“4546.72”,
“公司”:“Juan Vivas Higher”,
“productRef”:“CAR”,
“产品说明”:“洗涤剂特别是抗静电剂”
},
“关键1”:{
“dateTransaction”:“1377421074”,
“日期账单”:“1385373474”,
“单位”:“137”,
“价格单位”:“8.99”,
“金额”:“1231.63”,
“公司”:“2000年汽车展”,
“productRef”:“BRICAR”,
“productDesc”:“Cera hidrofugante para túneles de lavado”
},
“状态”:“成功”
}
}
}
我不知道如何从这个Json中获取元素。如果有人能帮我做这件事

我试图处理来自th jqGrid文档的这段代码,但没有得到任何结果

jQuery(document).ready(function(){
jQuery(“网格”).jqGrid({
url:“url…”,
数据类型:“json”,
mtype:“获取”,
colname:['Fecha Trans','Fecha Pago','Cliente'],
colModel:[
{名称:'dateTransaction',索引:'dateTransaction',宽度:100,可编辑:true},
{名称:'dateBilling',索引:'dateBilling',宽度:100,可编辑:true},
{名称:'company',索引:'company',宽度:100,可编辑:true}
],
jsonReader:{
重复项:false
},
rowNum:10,
行列表:[10,20,30],
pager:jQuery(“#pager”),
sortname:'名称',
viewrecords:是的,
排序器:“asc”,
标题:"标题",,
editurl:'url…'
}).navGrid(“#寻呼机”);
});
如果有人能告诉我这个JSON的正确语法,我可以做其余的事情


谢谢

您必须将服务器返回的JSON数据转换为jqGrid可以读取的项目数组。此外,我建议您使用
loadonce:true
选项,以便您可以在jqGrid内部使用本地分页、排序和筛选/搜索

例如,您可以通过将
jsonReader
root
部分定义为函数来转换输入数据。或者,您可以在处理前使用
回调来更改服务器响应。例如,您可以使用以下
jsonReader

jsonReader:{
根:函数(obj){
变量输入=obj.API_ICDFactory.API_getDataSample,p,res=[],项;
for(输入中的p){
项目=输入[p];
if(input.hasOwnProperty(p)&&typeof item==“object”){
item.id=p;
物品推送;
}
}
返回res;
},
重复项:false
}
展示我的建议。它显示

我使用的完整代码可以在下面找到:

$(function () {
    "use strict";
    var intTemplate = { width: 100, formatter: "integer", sorttype: "integer", align: "right" };
    $("#grid").jqGrid({
        url: "victorgb6.json",
        datatype: "json",
        colNames: ["Fecha Trans", "Fecha Pago", "Cliente"],
        colModel: [
            { name: "dateTransaction", template: intTemplate },
            { name: "dateBilling", template: intTemplate },
            { name: "company" }
        ],
        cmTemplate: {width: 250, editable: true},
        gridview: true,
        height: "auto",
        autoencode: true,
        loadonce: true,
        jsonReader: {
            root: function (obj) {
                var input = obj.API_ICDFactory.API_getDataSample, p, res = [], item;
                for (p in input) {
                    item = input[p];
                    if (input.hasOwnProperty(p) && typeof item === "object") {
                        item.id = p;
                        res.push(item);
                    }
                }
                return res;
            },
            repeatitems: false
        },
        rowNum: 10,
        rowList: [10, 20, 30],
        pager: "#pager",
        viewrecords: true,
        caption: "Title",
        editurl: "myEditUrl"
    }).jqGrid("navGrid", "#pager");
});

您必须将服务器返回的JSON数据转换为jqGrid可以读取的项目数组。此外,我建议您使用
loadonce:true
选项,以便您可以在jqGrid内部使用本地分页、排序和筛选/搜索

例如,您可以通过将
jsonReader
root
部分定义为函数来转换输入数据。或者,您可以在处理前使用
回调来更改服务器响应。例如,您可以使用以下
jsonReader

jsonReader:{
根:函数(obj){
变量输入=obj.API_ICDFactory.API_getDataSample,p,res=[],项;
for(输入中的p){
项目=输入[p];
if(input.hasOwnProperty(p)&&typeof item==“object”){
item.id=p;
物品推送;
}
}
返回res;
},
重复项:false
}
展示我的建议。它显示

我使用的完整代码可以在下面找到:

$(function () {
    "use strict";
    var intTemplate = { width: 100, formatter: "integer", sorttype: "integer", align: "right" };
    $("#grid").jqGrid({
        url: "victorgb6.json",
        datatype: "json",
        colNames: ["Fecha Trans", "Fecha Pago", "Cliente"],
        colModel: [
            { name: "dateTransaction", template: intTemplate },
            { name: "dateBilling", template: intTemplate },
            { name: "company" }
        ],
        cmTemplate: {width: 250, editable: true},
        gridview: true,
        height: "auto",
        autoencode: true,
        loadonce: true,
        jsonReader: {
            root: function (obj) {
                var input = obj.API_ICDFactory.API_getDataSample, p, res = [], item;
                for (p in input) {
                    item = input[p];
                    if (input.hasOwnProperty(p) && typeof item === "object") {
                        item.id = p;
                        res.push(item);
                    }
                }
                return res;
            },
            repeatitems: false
        },
        rowNum: 10,
        rowList: [10, 20, 30],
        pager: "#pager",
        viewrecords: true,
        caption: "Title",
        editurl: "myEditUrl"
    }).jqGrid("navGrid", "#pager");
});

您好,我使用了您的代码,它与一个本地文件一起工作,但是当我尝试从服务器获取JSON时,却什么都没有做。首先,我得到了一个错误:访问控制不允许使用Origin Allow Origin,但我想我用了一个代理文件解决了这个问题,我在这篇文章中读到了,我现在没有得到错误,但是得到了nodata。我必须得到JSON的服务器Url是:嗨,我使用了你的代码,它使用了一个本地文件,但当我尝试从服务器获取JSON时,什么都做不了。首先,我得到了一个错误:访问控制不允许使用Origin Allow Origin,但我想我使用了一个代理文件解决了这个问题,我在这篇文章中读到了这个文件,我现在没有得到错误,但是得到了nodata。我必须得到JSON的服务器的Url是: