Census CensusGetDistrictsJSON.php - jcobban/Genealogy GitHub Wiki
This script returns a JSON document describing the census districts defined for a particular census and province.
Parameters (passed by method=get):
Name | Description |
---|---|
Census | 2 character country code plus 4 digit year |
Province | 2 letter province code within Canada if only the districts within a specific province are requested. |
State | 2 letter state code if only districts within a specific state are requested. |
Lang | preferred language of communication |
An example listing the districts within New Brunswick for the 1881 census.
{
"get" : {"census": "CA1881", "province": "NB"},
"Albert-23" : "Albert (NB)",
"Carleton-31" : "Carleton (NB)",
"Charlotte-26" : "Charlotte (NB)",
"Gloucester-36" : "Gloucester (NB)",
"Kent-34" : "Kent (NB)",
"King's-27" : "King's (NB)",
"Northumberland-35" : "Northumberland (NB)",
"Queen's-28" : "Queen's (NB)",
"Restigouche-37" : "Restigouche (NB)",
"Saint John-25" : "Saint John (NB)",
"Saint John City-24" : "Saint John City (NB)",
"Sunbury-29" : "Sunbury (NB)",
"Victoria-32" : "Victoria (NB)",
"Westmorland-33" : "Westmorland (NB)",
"York-30" : "York (NB)"
}
Note that the key of each member of the response object is a concatenation of the district name and the district number. This is required because a JSON document behaves like a JavaScript object and without the district name the members of the object would be presented to the application in the numeric order of the district numbers, which would be inconvenient for users. Furthermore characters in the district name which could could interfere with the interpretation of the data are encoded, and this must be reversed for the data is presented to the user. The Javascript code to process the response to this script looks like:
function gotDistFile(jsonDoc)
{
...
for (let distid in jsonDoc)
{
if (distid == 'get')
continue;
// get the district name to display to the user
let name = jsonDoc[distid]; // district name
let result = /[0-9.]+$/.exec(distid);
if (result)
distid = result[0];
let textarea = document.createElement('textarea');
textarea.innerHTML = name;
name = textarea.value; // decode HTML
Next: CensusGetSubDists.php