以下是我的代码,我想获取 JSON 数据,我正在 Office 365 Napa 中做一个铁路应用程序,我的 JSON 正在加载但没有向我显示数据,我正在传递在字符串中传递的车站代码HMAC 签名是通过在 URL 中传递它来生成的,我得到了我必须阅读的 JSON,
'use strict';
var context = SP.ClientContext.get_current();
var user = context.get_web().get_currentUser();
(function () {
// This code runs when the DOM is ready and creates a context object which is
// needed to use the SharePoint object model
$(document).ready(function ()
{
getUserName();
$("#button1").click(function()
{
paraupdate();
});
});
// This function prepares, loads, and then executes a SharePoint query to get
// the current users information
function paraupdate()
{
var str=""+$("#textbox1").val();
alert(""+str);
var message = str+"json539ff0f815ca697c681fe01d32ba52e3";
var secret = "<my private key>";
var crypto = CryptoJS.HmacSHA1(message, secret).toString();
alert("crypto answer is " + crypto);
var siteurl="http://pnrbuddy.com/api/station_by_code/code/"+str+"/format/json/pbapikey/539ff0f815ca697c681fe01d32ba52e3/pbapisign/"+crypto;
$.getJSON(
siteurl,
function(data){
alert(data.message);
});
}
function getUserName()
{
context.load(user);
context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
}
// This function is executed if the above call is successful
// It replaces the contents of the 'message' element with the user name
function onGetUserNameSuccess()
{
$("#label1").html("Enter Station Code : ");
$("#button1").val("CLICK");
}
// This function is executed if the above call fails
function onGetUserNameFail(sender, args) {
alert('Failed to get user name. Error:' + args.get_message());
}
})();
JSON 响应是:
{
"response_code": 200,
"stations": [
{
"name": "Kanpur Central",
"code": "CNB",
"state": "UP",
"zip": null,
"railway_zone": "",
"location": {
"lat": "26.4528466",
"lng": "80.3237478"
},
"about_text": null,
"about_link": null
},
{
"name": "Chandari",
"code": "CNBI",
"state": "UP",
"zip": null,
"railway_zone": "",
"location": {
"lat": "26.4279135",
"lng": "80.3604594"
},
"about_text": null,
"about_link": null
}
]
}