简体   繁体   English

格式化JSON文件以读取localhost?

[英]Format JSON file to be read localhost?

I dont know if I am formatting my .json wrong but I am using backbone.js and cannot pass in the url to my json file. 我不知道我的.json格式是否错误,但我使用的是ribs.js,无法将url传递给我的json文件。

PlayersCollection = Backbone.Collection.extend({
      model: Player,
      url: 'http://localhost/STEPS/data/players.json',
      //localStorage: new Backbone.LocalStorage("players-backbone"),
});

The .json looks like a standard json format. .json看起来像标准的json格式。

[
    {
         name: 'Kobe Bryant',
         team: 'Los Angeles Lakers',
         team_id: 1,
         number: 24
    },
    {
         name: 'Lebron James',
         team: 'Miami Heat',
         team_id: 2,
         number: 6
    }
]

I just copied and pasted that into a blank file then saved it as players.json I felt maybe there is more to it than that. 我只是将其复制并粘贴到一个空白文件中,然后将其保存为players.json,我觉得可能不止于此。 I searched the web but I just want a simple way to store a dummy .json file in my localhost for access via url in backbone. 我在网上搜索,但我只想要一种简单的方法来在我的本地主机中存储一个虚拟.json文件,以便通过主干网中的url访问。

In a tutorial I followed a while back the url they targeted was this http://backbonejs-beginner.herokuapp.com/users 在教程中,我跟踪了一段时间,他们定位的网址是http://backbonejs-beginner.herokuapp.com/users

You probably want the JSON to look something like this. 您可能希望JSON看起来像这样。 At least this is valid. 至少这是有效的。

{ "players": [
    {
        "name": "Kobe Bryant",
        "team": "Los Angeles Lakers",
        "team_id": 1,
        "number": 24
    },
    {
        "name": "Lebron James",
        "team": "Miami Heat",
        "team_id": 2,
        "number": 6
    }
]}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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