2016-06-24 3 views
-2

Ich habe dieses JSON-ObjektWie kann ich alle Daten in dieser Antwort lesen?

{ 
    "0": { 
    "id": "44", 
    "date": "2016-06-24 10:53:08", 
    "client_id": "44", 
    "status": "waiting", 
    "price": null, 
    "paid": null, 
    "client": false, 
    "items": { 
     "beirut": { 
     "52": { 
      "id": "52", 
      "type": "Kerosene", 
      "quantity": "50", 
      "price": "20100", 
      "address": "beirut" 
     } 
     } 
    } 
    }, 
    "1": { 
    "id": "42", 
    "date": "2016-06-24 10:43:35", 
    "client_id": "44", 
    "status": "waiting", 
    "price": null, 
    "paid": null, 
    "client": false, 
    "items": { 
     "beirut": { 
     "50": { 
      "id": "50", 
      "type": "Super 98", 
      "quantity": "60", 
      "price": "34900", 
      "address": "beirut" 
     } 
     } 
    } 
    }, 
    "status": "ok" 
} 

Ich möchte lesen alle Daten aus dieser Antwort in Javascript.

Dies wird in einem jquery.ajax Anruf als datatype:jsonp zurückgegeben. Ich bin in der Lage, auf Daten zugreifen, und das zeigt alle speichert in HTML-Seite.

Wie kann ich das richtig lesen?

+0

Was ist Ihr Hauptproblem ist, diese Daten beim Lesen? – iomv

+0

Wenn es JSONP ist, muss die Antwort Callback-Funktion wie 'Callback ({...}) 'enthalten, im Moment ist es nicht JSONP, sondern nur JSON. – jcubic

+0

Willkommen bei SO. Bitte besuche die [Hilfe] und nimm die [Tour], um zu sehen, was und wie man fragt. TIPP: Sende Aufwand und Code. Im Moment sehen wir kein Problem. – mplungjan

Antwort

0

// Code goes here 
 

 
var obj = { 
 
    "0": { 
 
    "id": "44", 
 
    "date": "2016-06-24 10:53:08", 
 
    "client_id": "44", 
 
    "status": "waiting", 
 
    "price": null, 
 
    "paid": null, 
 
    "client": false, 
 
    "items": { 
 
     "beirut": { 
 
     "52": { 
 
      "id": "52", 
 
      "type": "Kerosene", 
 
      "quantity": "50", 
 
      "price": "20100", 
 
      "address": "beirut" 
 
     } 
 
     } 
 
    } 
 
    }, 
 
    "1": { 
 
    "id": "42", 
 
    "date": "2016-06-24 10:43:35", 
 
    "client_id": "44", 
 
    "status": "waiting", 
 
    "price": null, 
 
    "paid": null, 
 
    "client": false, 
 
    "items": { 
 
     "beirut": { 
 
     "50": { 
 
      "id": "50", 
 
      "type": "Super 98", 
 
      "quantity": "60", 
 
      "price": "34900", 
 
      "address": "beirut" 
 
     } 
 
     } 
 
    } 
 
    }, 
 
    "status": "ok" 
 
} 
 

 
Object.keys(obj).forEach(function(key){ 
 
    
 
if (obj.hasOwnProperty(key)){ 
 
    console.log(key,obj[key]); 
 
} 
 
}) 
 

Verwandte Themen