2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【ajax】JqueryでJSONを一件ずつ取得する【なるほど】

Posted at

入れ子になっているjsonを一件ずつ取り出すのに苦労したのでまとめてみました。

入れ子になっているjson

ajaxでjsonを取得すると、多分こういう形になってる

{ 
  "lists": [
        {
            "text": "aaa",
            "name": "a",
            "created_at": "2020-03-16 09:02"
        },
        {
            "text": "bbb",
            "name": "b",
            "created_at": "2020-03-16 09:06"
        },
        {
            "text": "ccc",
            "name": "c",
            "created_at": "2020-03-16 09:06"
        }
    ]
}

これを一件ずつ取り出す


$(function(){
            $.ajax({
                url: 'http://localhost',
                type:'GET',
            }).done(function(data){
                    for(var i in data['lists']){
                        //textをひとずつ出力
                        console.log(data['lists'][n].text);
                        console.log(data['lists'][n].name);
                        console.log(data['lists'][n].created_at);
                    }
               });
            });


data['lists'][n].textここの部分すごく苦労した、、、

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?