2014-12-15 3 views
-4

JSON 객체에서 정보를 얻을 :나는이 JSON 개체가

[ 
{ 
    "debut": "08-12-2014", 
    "fin": "09-12-2014", 
    "date_inconnue": "", 
    "client_desactive": "0", 
    "numero_info_fact": "0" 
}, 
{ 
    "groupe_1": { 
     "infos": { 
      "commandes_id": "95", 
      "groupes_id": "143", 
      "lieu_depart": "Delta", 
      "lieu_arrivee": "Brugges", 
      "heure_depart": "9:00", 
      "heure_arrivee": "13:00", 
      "id": "143", 
      "nom": "Nijs", 
      "taille": "4" 
     }, 
     "langues": [ 
      { 
       "groupes_id": "143", 
       "langues_id": "2", 
       "id": "2", 
       "langue": "Néerlandais", 
       "statut": "0" 
      } 
     ], 
     "langues_guide": [ 
      { 
       "guides_id": "3", 
       "langues_id": "1" 
      }, 
      { 
       "guides_id": "3", 
       "langues_id": "2" 
      }, 
      { 
       "guides_id": "3", 
       "langues_id": "3" 
      } 
     ], 
     "activites": [], 
     "fournisseurs": [ 
      { 
       "groupes_id": "143", 
       "fournisseurs_id": "15", 
       "prix_achat": null, 
       "prix_vente": null, 
       "paye_par_bb": "1", 
       "remarque": "", 
       "id": "15", 
       "nom": "Cars Dessaintes", 
       "types_fournisseurs_id": "3", 
       "tel": "02 355 89 87", 
       "fax": "", 
       "adresse": "Chaussée de Tubize", 
       "cpostal": "1480", 
       "commune": "Saintes", 
       "fournisseurs_cat": [ 
        { 
         "id": "15", 
         "nom": "Cars Dessaintes", 
         "types_fournisseurs_id": "3", 
         "tel": "02 355 89 87", 
         "fax": "", 
         "adresse": "Chaussée de Tubize", 
         "cpostal": "1480", 
         "commune": "Saintes" 
        }, 
        { 
         "id": "1", 
         "nom": "Cars Rent", 
         "types_fournisseurs_id": "3", 
         "tel": "0474 74 74 74", 
         "fax": "0474 75 75 75", 
         "adresse": "Rue Lambin 52", 
         "cpostal": "1050", 
         "commune": "Ixelles" 
        } 
       ] 
      } 
     ], 
     "guides": [ 
      { 
       "guides_id": "3", 
       "nom": "Kiss", 
       "prenom": "Robert", 
       "remarque": "", 
       "id": "756", 
       "prestations": [ 
        { 
         "id": "60", 
         "nom": "Brel", 
         "types_activites_id": "1", 
         "remarque": "Quel bon guide..." 
        } 
       ] 
      } 
     ], 
     "contacts": [ 
      { 
       "id": "41", 
       "remarque_contact_groupe": "Ne me quitte pas", 
       "telephone_contact_groupe": "03 888 77 78", 
       "mail_contact_groupe": null, 
       "prenom_contact_groupe": null, 
       "nom_contact_groupe": "Jacques Brel", 
       "gsm_contact_groupe": null, 
       "groupe_id": "143" 
      }, 
      { 
       "id": "42", 
       "remarque_contact_groupe": "Oh mon Dieu", 
       "telephone_contact_groupe": "02 888 78 98", 
       "gsm_contact_groupe": null, 
       "groupe_id": "143" 
      } 
     ] 
    }, 
    "groupe_2": { 
     "infos": { 
      "commandes_id": "95", 
      "groupes_id": "147", 
      "lieu_depart": "RTL HOUSE", 
      "lieu_arrivee": "", 
      "id": "147", 
      "nom": "RTL", 
      "taille": "" 
     }, 
     "langues": [ 
      { 
       "groupes_id": "147", 
       "langues_id": "3", 
       "id": "3", 
       "langue": "Anglais", 
       "statut": "0" 
      } 
     ], 
     "langues_guide": [ 
      { 
       "guides_id": "1", 
       "langues_id": "1" 
      }, 
      { 
       "guides_id": "1", 
       "langues_id": "3" 
      } 
     ], 
     "activites": [], 
     "fournisseurs": [], 
     "guides": [ 
      { 
       "guides_id": "1", 
       "nom": "Mets", 
       "prenom": "Anthony", 
       "remarque": "rthdgfhgfh dgdgdsgf", 
       "id": "757", 
       "prestations": [ 
        { 
         "id": "127", 
         "nom": "Bourgmestres", 
         "types_activites_id": "1", 
         "remarque": "" 
        } 
       ] 
      } 
     ], 
     "contacts": [ 
      { 
       "id": "58", 
       "remarque_contact_groupe": "La plus belle !!!", 
       "telephone_contact_groupe": "", 
       "mail_contact_groupe": null, 
       "prenom_contact_groupe": null, 
       "nom_contact_groupe": "Pandeville Sophie", 
       "gsm_contact_groupe": null, 
       "groupe_id": "147" 
      } 
     ] 
    } 
},** 
[ 
    { 
     "id": "646", 
     "id_commande": "95", 
     "id_guide": "3", 
     "heures_supplementaires": "0", 
     "paiement_sur_place": "1", 
     "remarque": "", 
     "payements": [], 
     "factures": [], 
     "ardoises": [] 
    }, 
    { 
     "id": "647", 
     "id_commande": "95", 
     "id_guide": "1", 
     "heures_supplementaires": "0", 
     "paiement_sur_place": "1", 
     "remarque": "", 
     "payements": [], 
     "factures": [], 
     "ardoises": [] 
    } 
], 
[ 
    [ 
     { 
      "id": "1", 
      "titre": "0", 
      "nom": "Cornette", 
      "prenom": "Arielle", 
      "fonction": "", 
      "nom_societe": "", 
      "status_id": "2", 
      "langues_id": "1", 
      "tva": "", 
      "client_id": "0", 
      "client_desactive": "0", 
      "remarque": "RAF", 
      "numero_info_fact": "0", 
      "langue": "Français", 
      "statut": "0" 
     }, 
     { 
      "id": "1", 
      "rue": "rue de l'Abattoir#Près de la Mosquée#Grand Duplex", 
      "numero": "4", 
      "boite": "5", 
      "cp": "1070", 
      "ville": "Anderlecht", 
      "mail": "[email protected]", 
      "telephone": "02 676 78 78", 
      "gsm": "0467 76 78 90", 
      "fax": "02 650 59 59", 
      "types_informations_contact_id": "1", 
      "clients_id": "60", 
      "pays_id": "1", 
      "pays": "Belgique" 
     } 
    ], 
    [ 
     { 
      "id": "7", 
      "gsm_contact_client": "0467 76 78 90", 
      "fax_contact_client": "02 650 59 59", 
      "telephone_contact_client": "02 676 78 78", 
      "mail_contact_client": "[email protected]", 
      "prenom_contact_client": "Arielle", 
      "nom_contact_client": "Cornette", 
      "clients_id": "60", 
      "remarque": "" 
     }, 
     { 
      "id": "8", 
      "gsm_contact_client": "0478 76 78 78", 
      "fax_contact_client": "", 
      "telephone_contact_client": "02 786 78 78", 
      "mail_contact_client": "[email protected]", 
      "prenom_contact_client": "Alice", 
      "nom_contact_client": "Boutboul", 
      "clients_id": "60", 
      "remarque": "BELLE-FILLE" 
     } 
    ] 
] 

]

나는 그 정보 좀하고 싶습니다

:

나는 여러 가지 시도

{ 
    "groupe_1": { 
     "infos": { 
to 

"gsm_contact_groupe": null, 
       "groupe_id": "147" 

에서을 방법,하지만 나는 json objet의이 부분을 얻을 수 없습니다. 나는 큰 JSON의 오브제를 검색해야 할 때

run_in_tree(retour[1]); 

       function run_in_tree(obj) 
       { 
        for (key in obj) 
        { 

         $("#info_groupes").after('Key => '+obj[key]); 
         $("#info_groupes").after("<br>"); 
         if (typeof obj[key] == 'object') run_in_tree(obj[key]); 
        } 
       } 

는 내가 어떤 어려움이

(키와 값) 정보를 얻을 수 아니에요.

+0

코드에 ** **가 무엇입니까? 당신이 그것을 과감하게 만들려고 했습니까? – vaso123

답변

0

우선, 배열이있는 것 같습니다. 이 배열의 두 번째 객체는 각 그룹에 대한 속성을 포함하고있는 것으로 보입니다.

그래서 그룹을 반복, 당신은이 작업을 수행 할 것입니다 :

var groups = obj[1];// Get the 2nd object; 

for(var key in groups){ 
    var group = groups[key]; 
    console.log(group.infos.commandes_id); 
} 

당신은 너무 하위 개체의 속성을 반복하는이 같은 논리를 사용할 수 있습니다. 예를 들어, 모든 infos 데이터를 기록 할 경우 :

for(var i = 0; i < group.contacts.length; i++){ 
    var contact = group.contacts[i]; 
    console.log(contact.id); 
} 

이 같은 큰 JSON 사용하여 작업하는, 그 사이의 차이를 기억하는 데 도움이 :

for(var infoKey in group.infos){ 
    var info = group.infos[infoKey]; 
    console.log(infoKey + " = " + info); 
} 

및 연락처 배열을 반복 배열 []과 객체 {}을 다른 방법으로 액세스하려는 경우 (위 그림 참조).

희망하시는 곳으로 가는데 도움이되는 희망

+1

코드와 설명이 완벽합니다. 감사합니다. – user3553866

관련 문제