samayo/

country-json

简单但实用的世界(按国家)JSON格式数据

安装次数: 18,109

依赖: 0

建议者: 0

安全: 0

星标: 1,068

关注者: 22

分支: 804

开放问题: 2

语言:JavaScript

v2.2.7 2024-08-31 11:14 UTC

This package is auto-updated.

Last update: 2024-08-31 11:15:57 UTC


README

世界(按国家)的简单数据,每个数据都以JSON格式表示。

下载

使用npm

$ npm install country-json

或composer

$ composer require samayo/country-json

或git

$ git clone https://github.com/samayo/country-json

提供在JSON格式下的内容列表

使用方法

使用各种语言展示/集成数据的示例。

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'}
  }
}

贡献

随时发送PR来修复、更新或添加新条目。对于非次要更改(例如:国家:名称、语言、城市、独立日期等),如果可能,请包括来源。

资源