Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

省市区编码及使用Node按行解析生成市区对应Map #17

Closed
shiiiiiiji opened this issue May 24, 2018 · 1 comment
Closed

省市区编码及使用Node按行解析生成市区对应Map #17

shiiiiiiji opened this issue May 24, 2018 · 1 comment

Comments

@shiiiiiiji
Copy link
Owner

shiiiiiiji commented May 24, 2018

省市区编码.txt


相关资源:

@shiiiiiiji shiiiiiiji changed the title 省市区编码 省市区编码及使用Node按行解析生成市区对应Map May 24, 2018
@shiiiiiiji
Copy link
Owner Author

shiiiiiiji commented May 24, 2018

  • 使用readLine库按行解析
var fs = require('fs');
var readLine = require('lei-stream').readLine;

const cityArr = {};
readLine('./myfile.txt').go(function (data, next) {
    let _tmpArr = data.split('	');
    if(_tmpArr[0] && !(_tmpArr[0]%10000)){
        console.log(_tmpArr[0]%10000);
        console.log('市');
        cityArr[_tmpArr[1]] = {};
        cityArr[_tmpArr[1]].name = _tmpArr[2].replace('\r', '');
        cityArr[_tmpArr[1]].areaArr = [];
    }

    if(_tmpArr[0] && (_tmpArr[0]%10000) && !(_tmpArr[0]%100)){
        console.log('区');
        cityArr[_tmpArr[0]].areaArr.push({
            name: _tmpArr[1],
            code: _tmpArr[2].replace('\r', '')
        });
    }
    
    next();
}, function () {
    fs.writeFile('res', JSON.stringify(cityArr));
    console.log('end');
});

参考链接:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant