簡體   English   中英

用jquery調用json對象內的元素

[英]call an element inside json object with jquery

我正在嘗試在json對象中調用元素,這是代碼的一部分

{
    " academy": {
        "business": {
            "E-commerce": [

現在,通過此代碼,我成功地將academy作為第一個要素

$.getJSON("professorUnversityCollegeCourseData.js", function(property) {
$.each(property, function (key, value) {
    $('#uni').add('<option value="'+ key + '" id="'+ count +'">'+ key +  
                  '</option>').appendTo('#university-selection');
    arrayUni[count] = key;
    count++;
});

我現在如何獲得“業務”元素?

我認為您應該這樣做:

$.getJSON("professorUnversityCollegeCourseData.js", function(property){
    business = property.academy.business;
     //-or-
    business = property["academy"]["business"];
});

(根據您在此處存儲的數據。)

你嘗試過嗎:

$.getJSON("professorUnversityCollegeCourseData.js", function(property) {
    $.each(property, function (key, value){
        $('#uni').add('<option value="'+ key + '" id="'+ count +'">'+ key + '</option>').appendTo('#university-selection');
        arrayUni[count] = key;
        count++;
        alert(this.academy.business);//Or also this['academy']['business']
    });
    alert(property.academy.business);//Or also property['academy']['business']
});

我想這就是你所追求的

key.academy.business

真的就是這么簡單,或:

key['academy'] 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM