SyntaxError:解析json响应的无效标签

时间:2013-05-21 12:59:25

标签: jquery json web-services rest

我从我的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
            }
        }
    }
}

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

这个代码我试图运行。

                                   $(文件)。就绪(函数(){                 $就({                     网址:'http://fake.server.se/skywin-ws-1.4.0/rest/skywin/member/getMember?memberNo=20878&_type=json',                     dataType:'jsonp',                     成功:功能(SkyWinResponse){                       $ .each(data.SkyWinResponse.results.result,function(i,item)               {                  $('#response')。append(i +“:”+ item +“
”);               });                     }                 });             })                                 

1 个答案:

答案 0 :(得分:0)

您的JSON似乎有效。你想做这样的事情:

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

JSFiddle