【问题标题】:Using $.getJSON for getting json data in pagebeforeshow is not working in jquery mobile使用 $.getJSON 在 pagebeforeshow 中获取 json 数据在 jquery mobile 中不起作用
【发布时间】:2014-10-14 05:22:38
【问题描述】:

我已使用 $.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"
                    }
                ]
            }
        }
    }
}

谁能帮帮我,谢谢。

【问题讨论】:

  • 您的 IP 地址中是否缺少任何内容? 192.168.
  • 没有,只是我刚刚在添加时删除了它
  • 如果您直接在浏览器中检查 URL ...一切正常吗? consol 有什么错误吗?
  • 显示一些解析错误

标签: javascript jquery json jquery-mobile


【解决方案1】:

您的 JSON 包含语法错误,请查看您的“fieldInfo”节点。您没有用 , 分隔您的差异对象,

例子:

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

而不是

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

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

【讨论】:

    猜你喜欢
    • 2013-03-16
    • 1970-01-01
    • 2013-05-17
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    相关资源
    最近更新 更多