项目
在 GitHub 查看 country-json
samayo/country-json
关于
按国家整理的简明世界数据,每个国家均采用 JSON 格式。
开发工具实测星标增长
- 24小时
- 0
- 7天
- +2
- 15天
- +3
- 1个月
- +6
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文country-json 
A simple data of the world (by country) each in JSON format.
Download
Using npm
$ npm install country-json
or composer
$ composer require samayo/country-json
or git
$ git clone https://github.com/samayo/country-json
List of contents provided in JSON formats:
- Country by Name
- Country by Abbreviation
- Country by Alphabet Letters
- Country by Avg Male Height
- Country by Barcode Prefix
- Country by Calling Code
- Country by Capital City
- Country by Cities
- Country by Continent
- Country by Coastline
- Country by Currency Name
- Country by Religion
- Country by Currency Code
- Country by Domain Tld
- Country by Driving Side
- Country by Elevation
- Country by Flag
- Country by Geo Coordinates
- Country by Government Type
- Country by Independence Date
- Country by Iso Numeric
- Country by Landlocked
- Country by Languages
- Country by Life Expectancy
- Country by National Symbol
- Country by National Dish
- Country by Population Density
- Country by Population
- Country by Region In World
- Country by Surface Area
- Country by Yearly Average Temperature
Usage
Examples using various languages on how display/integrate the data.
PHP
$file = file_get_contents("./src/country-by-capital-city.json");
foreach (json_decode($file, true) as $key => $value) {
var_dump($value); // { country: 'Afghanistan', city: 'Kabul' ..}
}
Node.js
var cities = require('./src/country-by-capital-city.json')
console.log(cities[0]); // { country: 'Afghanistan', city: 'Kabul' }
Ruby
require 'json'
file = File.read('./src/country-by-capital-city.json')
json = JSON.parse(file)
puts json[0] # {"country"=>"Afghanistan", "city"=>"Kabul"}
Python
import yaml
with open('./src/country-by-capital-city.json') as json_file:
for line in yaml.safe_load(json_file):
print line # {'country': 'Afghanistan', 'city': 'Kabul'}
Golang
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
)
func main() {
data, err := ioutil.ReadFile("path/to/country-by-capital-city.json")
if err != nil {
panic(err)
}
var entries []struct{ Country, City string }
if err = json.Unmarshal(data, &entries); err != nil {
panic(err)
}
for _, entry := range entries {
fmt.Println(entry.Country, entry.City) # {'country': 'Afghanistan', 'city': 'Kabul'}
}
}
Contribution
Feel free to send a PR to fix, update or add new entry anytime. For non-minor changes (ex: country: name, language, city, independence date..), please include a source, if possible.
Resources
探索相关项目
加载中…