简体   繁体   中英

How to get the data in Json Array? -Backbone js

Im currently working on Backbone js that reads json.. I get the json in the api using JSON.stringify and it displays as JSON but when i get the display_name it gets undefined

This is my JSON Result(this json is from my dropbox API)

 [  
   {  
      "referral_link":"https://db.tt/JnPooKxuE1",
      "display_name":"Sample APP",
      "uid":638229321,
      "locale":"en",
      "team":null,
      "quota_info":{  
         "datastores":0,
         "shared":0,
         "quota":2147483648,
         "normal":9972222
      },
      "is_paired":false,
      "country":"EU",
      "name_details":{  
         "familiar_name":"Sample",
         "surname":"App",
         "given_name":"Sample"
      },
      "email":"sample@gmail.com"
   }
]

This is the code when i get my json using backbone js

$(function(){


              var access_token1 = 'my token';

             var Profile = Backbone.Model.extend();

             var ProfileList = Backbone.Collection.extend({
               model: Profile,
               url: 'https://api.dropboxapi.com/1/account/info'
             });

                var setHeader = function (xhr) {
                     xhr.setRequestHeader('Content-Type', 'application/json');
                       xhr.setRequestHeader("Authorization", 'Bearer ' + access_token1);
                    }



             var profiles = new ProfileList();

             /*var jsontree = JSON.stringify(profiles);*/


             profiles.fetch({ beforeSend: setHeader });
            profiles.bind('reset', function () {


                        var result = JSON.stringify(profiles.models);


                /*        document.getElementById("demo").innerHTML = result[0];*/
                          console.log(result);




              });
      });

由于数组中有一个对象,因此需要在选择对象键之前选择数组中的第一项。

result[0]["display_name"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM