【问题标题】:SyntaxError: invalid label parsing json responseSyntaxError:无效的标签解析 json 响应
【发布时间】:2013-05-21 12:59:24
【问题描述】:

我正在通过我的 WS 请求从 jquery 得到这个响应。

{
    "SkyWinResponse": {
        "statuscode": 0,
        "message": "ok\n ",
        "rowsaffected": 1,
        "results": {
            "result": {
                "@xsi.type": "member",
                "accountCreditLimit": 0,
                "accountNo": 1000001,
                "address1": "Annavägen 10",
                "addressChangeDate": "2013-04-12",
                "balance": 2068,
                "balanceCurrency": "kr",
                "certificateText": "PK",
                "climateCompensate": 2,
                "club": "UFK",
                "contactName": "Last, Andreas",
                "contactPhone": "090-123456",
                "countryCode": "SE",
                "countryNameLocalized": "Sverige",
                "createdDate": "2013-04-11",
                "credit": false,
                "dateOfBirth": "1971-05-04",
                "emailAddress": "first.last@ufk.nu",
                "firstJumpDate": "2013-04-27",
                "firstName": "First",
                "gender": "M",
                "hideAccountInRequest": false,
                "honorary": false,
                "infoViaEmail": true,
                "instructorText": "HL HM KL",
                "internalNo": 1,
                "jumpNo": 0,
                "lastName": "Nylund",
                "lastUpd": "2013-05-18 15:58:23.0",
                "licenseType": "C",
                "markedForLabel": false,
                "memberList": false,
                "memberListOverride": true,
                "memberNo": 20878,
                "memberType": "M",
                "nationalityCode": "SE",
                "nationalityNameLocalized": "Sverige",
                "permanentCredit": false,
                "pilot": false,
                "postCode": 91342,
                "postTown": "Obbola",
                "studentJumpNo": 0,
                "supporter": false,
                "userId": "Linda",
                "verifiedLicense": true,
                "video": false,
                "weight": 100,
                "weightUnit": "kg",
                "year": 2013
            }
        }
    }
}

但是当我尝试解析这个时,我只会得到无效的标签。任何关于如何读取每个条目 entry:value 并将它们显示在 html 页面中的建议。

这是我试图运行的代码。

$(文档).ready(函数(){ $.ajax({ 网址:'http://fake.server.se/skywin-ws-1.4.0/rest/skywin/member/getMember?memberNo=20878&_type=json', 数据类型:'jsonp', 成功:函数(SkyWinResponse){ $.each(data.SkyWinResponse.results.result, function(i, item) { $('#response').append(i + " : " + item + "
"); }); } }); })

【问题讨论】:

  • 你能告诉你代码的努力吗?

标签: jquery json web-services rest


【解决方案1】:

看来您的 JSON 是有效的。您是否正在尝试做这样的事情:

 $.each(data.SkyWinResponse.results.result, function(i, item)
 {
     $('#response').append(i + " : " + item + "<br>");
 });

JSFiddle

【讨论】:

  • 我从控制台调试中得到这个。
  • 尝试将function(SkyWinResponse)更改为function(data)
  • 发布一个指向 JSFiddle 或类似内容的链接,以便我可以提供帮助
  • 好的,所以这里的问题是,为了遵守跨域策略,您使用了 jsonp,但是 Web 服务正在返回 json 数据。因此,如果您可以修改 Web 服务或在同一域上获取请求页面,那将是一个开始
猜你喜欢
  • 1970-01-01
  • 2019-11-27
  • 1970-01-01
  • 1970-01-01
  • 2012-08-06
  • 2012-09-07
  • 2018-02-07
  • 2018-06-19
相关资源
最近更新 更多