我需要美国各州和各州县的列表

I need list of US states and counties of the state

我需要在正在处理的应用程序中包括当地的美国州和州县列表。那么有人可以让我知道在哪里可以找到要下载的 Json 或 .plist 格式的列表。

谢谢

只要你用心去做,你可以做任何你想做的事。

我已经为您编写了一个工具,用于从已知的更新源(维基百科)中提取这些数据。

代码可以从Github下载。

using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using HtmlAgilityPack;
using Newtonsoft.Json;

namespace GetCitiesCounties
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(@"Hitting Wikipedia");

            var uri = new Uri("https://en.wikipedia.org/wiki/List_of_United_States_counties_and_county_equivalents");
            var client = new HttpClient();
            var rs = client.GetAsync(uri).Result;
            if (rs.IsSuccessStatusCode)
            {
                var htmlContent = rs.Content.ReadAsStringAsync().Result;
                var htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(htmlContent);
                var list = new List<dynamic>();
                var nodes = htmlDoc.DocumentNode.SelectNodes("//table[@class='wikitable sortable']//tr");

                Console.WriteLine(@"Processing Rows");

                int rowIndex = 0;
                foreach (var row in nodes)
                {
                    if (rowIndex++ > 0)
                    {
                        var county = row.SelectNodes("td")[1].InnerText;
                        var state = row.SelectNodes("td")[2].InnerText;

                        list.Add(new
                        {
                            County = county,
                            State = state
                        });
                    }
                }

                var json = JsonConvert.SerializeObject(list);
                File.WriteAllText(@"C:\test.json", json);

                Console.WriteLine(@"Done, extracted cities and states to json file C:\test.json");
                Console.ReadLine();
            }
        }
    }
}

这是结果的一个片段。它显示了美国的每个县及其所属的州。

[
  {
    "County": "Autauga County",
    "State": "Alabama"
  },
  {
    "County": "Baldwin County",
    "State": "Alabama"
  },
  {
    "County": "Barbour County",
    "State": "Alabama"
  }
]

您可以在此处找到列表:https://www.webtoolz.online/resources/usa-list-of-states 此列表包含 JSON 格式的州名和缩写。