在pagebeforeshow中使用$ .getJSON获取json数据在jquery mobile中不起作用

时间:2014-10-14 05:22:38

标签: javascript jquery json jquery-mobile

我已经使用$ .getJSON在pagebeforeshow上获取json数据,但它不能正常工作。

$(document).on('pagebeforeshow', '#inpGrid', function(e) {
        alert("inpGrid");
        var tat_url = "http://192.168./html5/Demo/json/list.json";

              var url = "http://api.openweathermap.org/data/2.5/forecast?lat=35&lon=139&callback=?" ;
              $.getJSON(tat_url, function(res) {
                  console.log(res)

});

    });

代码如上所述,当在$ .getJSON中使用url时,它正在工作,而使用tat_url则无法正常工作。

http://192.168./html5/Demo/json/list.json如下:

{
    "response": {
        "respCode": 0,
        "output": {
            "delAction": "OP",
            "delTmplt": "sibcVizEdit",
            "title": "List TATs",
            "layout": "grid",
            "srvObjRef": "iawme1/IAWMblztnExpert-ListSIBCs_MB1412577249595",
            "startIndex": "0",
            "recsPerPage": "18",
            "noPages": "1",
            "curPageNo": "1",
            "fieldInfo": [
                {
                    "label": "Name",
                    "type": "STRING"
                }
                {
                    "label": "Alias",
                    "type": "STRING"
                }
                {
              "label": "Datatype",
               "type": "STRING"
                }
                {
            "label": "Default Value",
            "type": "STRING"
                }
                {
             "label": "Visibility",
            "type": "STRING"
                }
            ],
            "records": [
                {
                    "Name": "psngrType"
                    "Alias": "Pasngr Type"
                    "Datatype": "STRING"
                    "Default Value":"CC"
                    "Visibility": "0"
                },
                {
                    "Name": "flightNo"
            "Alias": "Flight No"
            "Datatype": "STRING"
            "Default Value":"$RV_flightNo"
                    "Visibility": "0"
                }
            ],
            "relServices": {
                "AServices": [
                    {
                        "ref": "IAWMblztnExpert-ListSIBCs-UpdateBizContext_MB",
                        "title": "Update SIBC",
                        "desc": "",
                        "srvRef": "IAWMblztnExpert-ListSIBCs-UpdateBizContext_MB",
                        "slctdOffsets": "0"
                    },
                    {
                        "ref": "IAWMblztnExpert-ListSIBCs-ListIICsInSIBC_MB",
                        "title": "List IICs",
                        "desc": "",
                        "srvRef": "IAWMblztnExpert-ListSIBCs-ListIICsInSIBC_MB",
                        "slctdOffsets": "0"
                    },
                    {
                        "ref": "IAWMblztnExpert-ListSIBCs-Deploy SIBC_MB",
                        "title": "Deploy",
                        "desc": "",
                        "srvRef": "IAWMblztnExpert-ListSIBCs-Deploy SIBC_MB",
                        "slctdOffsets": "0"
                    }
                ]
            }
        }
    }
}

有人可以帮助我,谢谢。

1 个答案:

答案 0 :(得分:0)

您的JSON包含语法错误,请查看您的'' fieldInfo''节点。你没有分开你的不同对象,

示例:

            {
                "label": "Name",
                "type": "STRING"
            },
            {
                "label": "Alias",
                "type": "STRING"
            }

而不是

            {
                "label": "Name",
                "type": "STRING"
            }
            {
                "label": "Alias",
                "type": "STRING"
            }

如果您需要轻松检查其余的json文件,请使用在线JSON验证器:http://jsonlint.com/