こんにちは、jQuery を使用して JSON ファイルを読み取るのは初めてです。次のコードを使用しています。
$.getJSON('updateProfile.js', function(data) {
var Options = [];
$.each(data.Options, function(key, val) {
alert('we have data for ' + val.id + ' and ' + val.label);
});
JSON 検証ツールを使用しましたが、ファイルは有効です。FF で chrome と firebug を使用して、ファイルが 200 ステータスになっていることを確認しました。ただし、.getJSON 呼び出しにブレーク ポイントを設定すると、コードがバイパスされます。
私はローカルのTomcatサーバーを使用しましたが、これを実際にサーバーに配置すると、すべて同じように実行されます。
ここに私が読もうとしているJSONがあります
{"Options":[
"title": "User Profile",
"description": "Your preferences can be modified below. Click on the section on the left. This will present the details on the right. Once you have updated your profile, click the Save button to save your changes.",
"id": "userprofileStackTabs",
"children": [
{
"id": "up001",
"linkID": "namePhones",
"label": "Name and Phones",
"description": "",
"default": "true"
},
{
"id": "up002",
"linkID": "password",
"label": "Password",
"description": " "
},
{
"id": "up003",
"linkID": "physAddrss",
"label": "Physical Address",
"description": " "
},
{
"id": "up004",
"linkID": "dfShippingAddrss",
"label": "Default Shipping Address",
"description": " "
},
{
"id": "up005",
"linkID": "cpgnPref",
"label": "Campaign Preferences",
"description": " "
},
{
"id": "up006",
"linkID": "appPref",
"label": "Application Preferences",
"description": " "
},
{
"id": "up007",
"linkID": "langPref",
"label": "Language Preferences",
"description": " "
},
{
"id": "up008",
"linkID": "agentLic",
"label": "Agent Licenses",
"description": " "
},
{
"id": "up009",
"linkID": "searchPref",
"label": "Search Preferences",
"description": " "
},
{
"id": "up010",
"linkID": "socMedAcct",
"label": "Social Media Accounts",
"description": " "
}
],
"buttons": [
{
"id": "upButn_Save",
"label": "Save"
},
{
"id": "upButn_Cancel",
"label": "Cancel"
}
]
]}
どんな助けでも大歓迎です。