Well, I have created an API and the output from http://localhost/lsapp4/public/api/articles in Postman is as follows:
{
"data": [
{
"id": 1,
"title": "Demo Article-1",
"body": "Happy Holidays1"
},
{
"id": 2,
"title": "Demo Article-2",
"body": "Happy Holidays2"
},
{
"id": 3,
"title": "Demo Article-3",
"body": "Happy Holidays3"
}
],
"links": {
"first": "http://lsapp4.test/api/articles?page=1",
"last": "http://lsapp4.test/api/articles?page=2",
"prev": null,
"next": "http://lsapp4.test/api/articles?page=2"
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 2,
"path": "http://lsapp4.test/api/articles",
"per_page": 3,
"to": 3,
"total": 4
}
}
How can I parse the title and body iteratively? I tried to do it like:
$.getJSON("http://localhost/lsapp4/public/api/articles",function(regen){
var i=0;
$.each(regen,function(index,item)
{
alert(item[i].title);
i=i+1;
});
});
But it did not work.
question from:
https://stackoverflow.com/questions/65545486/how-to-parse-json-from-api 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…