Wenn ich eine api
aufrufen, die ein zufälliges Zitat in json
Format zurückgibt (ein Titel und Inhalt), erhalte ich die json
ganz gut:Parsing json mit JavaScript nicht
ajax({ url: 'quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1', type: 'json' },
function(data) {
console.log((JSON.stringify(data)));
console.log(data.content);
console.log((JSON.stringify(data)));
Ausgänge:
[{
"ID":1562,
"title":"Michael Bierut",
"content":"Most of the mediocre design today comes from designers who are faithfully doing as they were taught in school: they worship at the altar of the visual.\n",
"link":"http:\/\/quotesondesign.com\/michael-bierut-3\/",
"custom_meta":{"Source":"article"}
}]
Aber console.log(data.content);
Ausgänge: keine.
Die Wurzel JSON-Wert nicht über eine ' "Inhalt"' Eigenschaft übereinstimmen 'data.content'. Es scheint "Daten" ist ein Array - 'console.log (Daten [0] .content)', etc. ([Access/Prozess (verschachtelte) Objekte, Arrays oder JSON] (http://stackoverflow.com/questions/ 11922383/access-process-nested-objects-arrays-or-json)) –
@RayonDabre Es ist nicht klar, dass dies jQuery ist. Trotz einiger Ähnlichkeiten scheinen die Argumente nicht mit 'jQuery.ajax()' kompatibel zu sein. –
@ JonathanLonowski, True! – Rayon