2017-07-15 6 views
0

では無視され、私はそれだけで完璧に動作し、JSONコメントフィールドはJSON.stringify

https://github.com/tellnes/node-apacheconf

にApacheの設定ファイルを解析するモジュールを使用しています。 JSON.stringify()を実行すると、結果のJSONオブジェクトにはコメントが含まれません。 console.log(config)の 出力:

{ ThreadsPerChild: [ '250', comments: [ [Array] ] ], 
    MaxRequestsPerChild: [ '0', comments: [ [] ] ], 
    Listen: [ '80', comments: [ [] ] ], 
    ServerRoot: [ '"/www/Apache22"', comments: [ [] ] ], 
    DocumentRoot: [ '"/THDL/thdl-site"', comments: [ [] ] ], 
    ServerName: [ 'localhost:80', comments: [ [Array] ] ], 
    ServerAdmin: [ '[email protected]', comments: [ [] ] ], 
    ErrorLog: [ 'logs/error.log', comments: [ [] ] ], 
    LogLevel: [ 'error', comments: [ [] ] ], 
    LoadModule: 
    [ 'alias_module modules/mod_alias.so', 
    'authz_host_module modules/mod_authz_host.so', 
    'autoindex_module modules/mod_autoindex.so', 
    'dir_module modules/mod_dir.so', 
    'log_config_module modules/mod_log_config.so', 
    'mime_module modules/mod_mime.so', 
    'rewrite_module modules/mod_rewrite.so', 
    'setenvif_module modules/mod_setenvif.so', 
    'php5_module "C:/www/php5/php5apache2.dll"', 
    comments: [ [Array], [Array], [Array], [Array], [Array], [], [Array], [], [] ] ], 
    IfDefine: 
    [ { '$args': 'SSL', LoadModule: [Array] }, 
    comments: [ [Array] ] ], 
    DefaultType: [ 'text/plain', comments: [ [] ] ], 
    IfModule: 
    [ { '$args': 'dir_module', DirectoryIndex: [Array] }, 
    { '$args': 'mime_module', 
     TypesConfig: [Array], 
     AddType: [Array] }, 
    { '$args': '!php5_module', IfModule: [Array] }, 
    { '$args': 'php5_module', Location: [Array] }, 
    { '$args': 'ssl_module', 
     Include: [Array], 
     SSLRandomSeed: [Array] }, 
    { '$args': 'mod_alias.c', Alias: [Array] }, 
    comments: [ [], [], [Array], [], [], [Array] ] ], 
    IndexIgnore: [ '.htaccess', comments: [ [] ] ], 
    FilesMatch: 
    [ { '$args': '^.ht', Order: [Array], Deny: [Array] }, 
    comments: [ [] ] ], 
    Redirect: [ '/thdl external link: http://localhost', comments: [ [] ] ], 
    Directory: 
    [ { '$args': '/', 
     Options: [Array], 
     AllowOverride: [Array], 
     Order: [Array], 
     Allow: [Array], 
     Satisfy: [Array] }, 
    { '$args': '/THDL/thdl-site', 
     Options: [Array], 
     AllowOverride: [Array], 
     Order: [Array], 
     Allow: [Array] }, 
    { '$args': 'C:/www/phpMyAdmin', 
     Options: [Array], 
     AllowOverride: [Array], 
     order: [Array], 
     deny: [Array], 
     allow: [Array] }, 
    comments: [ [], [Array], [] ] ], 
    Include: 
    [ 'conf/extra/httpd-autoindex.conf', 
    'conf/extra/httpd-languages.conf', 
    'conf/extra/httpd-info.conf', 
    'conf/extra/httpd-manual.conf', 
    'conf/extra/httpd-default.conf', 
    'conf/Suite-extra/components.conf', 
    comments: [ [Array], [Array], [Array], [Array], [Array], [Array] ] ], 
    LoadFile: [ '"C:/www/php5/php5ts.dll"', comments: [ [Array] ] ] } 

console.log(JSON.stringify(config))の出力:

{ 
    "ThreadsPerChild": [ 
    "250" 
    ], 
    "MaxRequestsPerChild": [ 
    "0" 
    ], 
    "Listen": [ 
    "80" 
    ], 
    "ServerRoot": [ 
    "\"/www/Apache22\"" 
    ], 
    "DocumentRoot": [ 
    "\"/THDL/thdl-site\"" 
    ], 
    "ServerName": [ 
    "localhost:80" 
    ], 
    "ServerAdmin": [ 
    "[email protected]" 
    ], 
    "ErrorLog": [ 
    "logs/error.log" 
    ], 
    "LogLevel": [ 
    "error" 
    ], 
    "LoadModule": [ 
    "alias_module modules/mod_alias.so", 
    "authz_host_module modules/mod_authz_host.so", 
    "autoindex_module modules/mod_autoindex.so", 
    "dir_module modules/mod_dir.so", 
    "log_config_module modules/mod_log_config.so", 
    "mime_module modules/mod_mime.so", 
    "rewrite_module modules/mod_rewrite.so", 
    "setenvif_module modules/mod_setenvif.so", 
    "php5_module \"C:/www/php5/php5apache2.dll\"" 
    ], 
    "IfDefine": [ 
    { 
     "$args": "SSL", 
     "LoadModule": [ 
     "ssl_module modules/mod_ssl.so" 
     ] 
    } 
    ], 
    "DefaultType": [ 
    "text/plain" 
    ], 
    "IfModule": [ 
    { 
     "$args": "dir_module", 
     "DirectoryIndex": [ 
     "index.html index.php index.aspx" 
     ] 
    }, 
    { 
     "$args": "mime_module", 
     "TypesConfig": [ 
     "conf/mime.types" 
     ], 
     "AddType": [ 
     "application/x-compress .Z", 
     "application/x-gzip .gz .tgz" 
     ] 
    }, 
    { 
     "$args": "!php5_module", 
     "IfModule": [ 
     { 
      "$args": "!php4_module", 
      "Location": [ 
      { 
       "$args": "/", 
       "FilesMatch": [ 
       { 
        "$args": ".php[45]?$", 
        "Order": [ 
        "allow,deny" 
        ], 
        "Deny": [ 
        "from all" 
        ] 
       } 
       ] 
      } 
      ] 
     } 
     ] 
    }, 
    { 
     "$args": "php5_module", 
     "Location": [ 
     { 
      "$args": "/", 
      "AddType": [ 
      "text/html .php .phps" 
      ], 
      "AddHandler": [ 
      "application/x-httpd-php .php", 
      "application/x-httpd-php-source .phps" 
      ] 
     } 
     ] 
    }, 
    { 
     "$args": "ssl_module", 
     "Include": [ 
     "conf/extra/httpd-ssl.conf" 
     ], 
     "SSLRandomSeed": [ 
     "startup builtin", 
     "connect builtin" 
     ] 
    }, 
    { 
     "$args": "mod_alias.c", 
     "Alias": [ 
     "/phpMyAdmin \"C:/www/phpMyAdmin\"" 
     ] 
    } 
    ], 
    "IndexIgnore": [ 
    ".htaccess" 
    ], 
    "FilesMatch": [ 
    { 
     "$args": "^.ht", 
     "Order": [ 
     "allow,deny" 
     ], 
     "Deny": [ 
     "from all" 
     ] 
    } 
    ], 
    "Redirect": [ 
    "/thdl external link: http://localhost" 
    ], 
    "Directory": [ 
    { 
     "$args": "/", 
     "Options": [ 
     "FollowSymLinks" 
     ], 
     "AllowOverride": [ 
     "all" 
     ], 
     "Order": [ 
     "deny,allow" 
     ], 
     "Allow": [ 
     "from all" 
     ], 
     "Satisfy": [ 
     "all" 
     ] 
    }, 
    { 
     "$args": "/THDL/thdl-site", 
     "Options": [ 
     "Indexes FollowSymLinks" 
     ], 
     "AllowOverride": [ 
     "all" 
     ], 
     "Order": [ 
     "allow,deny" 
     ], 
     "Allow": [ 
     "from all" 
     ] 
    }, 
    { 
     "$args": "C:/www/phpMyAdmin", 
     "Options": [ 
     "None" 
     ], 
     "AllowOverride": [ 
     "None" 
     ], 
     "order": [ 
     "deny,allow" 
     ], 
     "deny": [ 
     "from all" 
     ], 
     "allow": [ 
     "from 127.0.0.1" 
     ] 
    } 
    ], 
    "Include": [ 
    "conf/extra/httpd-autoindex.conf", 
    "conf/extra/httpd-languages.conf", 
    "conf/extra/httpd-info.conf", 
    "conf/extra/httpd-manual.conf", 
    "conf/extra/httpd-default.conf", 
    "conf/Suite-extra/components.conf" 
    ], 
    "LoadFile": [ 
    "\"C:/www/php5/php5ts.dll\"" 
    ] 
} 

コメントフィールドを完全に全体構造では無視されます。これを防ぐ方法を教えてください。

答えて

1

私はあなたがそのような配列のようなキーを使用できるとは思わない。

例えば、変更してみてください:

DefaultType: [ 'text/plain', comments: [ [] ] ], 

に:

DefaultType: { type: 'text/plain', comments: [ [] ] }, 

オブジェクト値を持つキーを含む:[ value1, value2 ]

オブジェクトができる:{ key1: value1, key2: value2 }

配列はカンマ区切り含みますまた、ar値の電子アレイ:{ key1: [ value1, value2 ] }

または多次元:{ key1: [ value1, [ value2, value3 ] ] }

それはあなたのconfigオブジェクトの構造に問題があるように見えます。私は私の例に合うように変更することをお勧めします。

関連する問題