返されたJSONフィードからすべてのキーと値のペアを出力しようとしていますが、ログ時にはundefined
しか取得できません。ノードGETリクエストからJSONを解析する
サンプルJSON:私はしようとしています
{ entityname: 'INTERNET SOLUTIONS INC, Delinquent June 1, 2014',
entityid: '20131032920',
agentfirstname: 'MARTIN',
entitystatus: 'Delinquent',
agentprincipalcountry: 'US',
agentprincipaladdress1: '10955 WESTMOOR DR.',
entitytypeverbatim: 'Corporation',
principalcountry: 'US',
agentprincipalstate: 'CO',
agentprincipalcity: 'WESTMINSTER',
principaladdress1: '608 CENTER DR.',
agentlastname: 'PELMORE',
principalcity: 'Los Angeles',
entityformdate: '2013-01-16T00:00:00',
agentprincipalzipcode: '80021',
principalstate: 'CA',
entitytype: 'DPC',
principalzipcode: '90045' }
コードを使用する:
const http = require('http');
http.get('http://data.colorado.gov/resource/4ykn-tg5h.json', function(res) {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
var body = "";
var newString = "";
res.on('data', function(d) {
body += d.toString();
});
res.on('end', function() {
newString = JSON.parse(body);
console.log('output', newString.entityid);
});
}).on('error', function(e) {
console.error(e);
});
私の予想される出力は次のようになります。
entityid: '20131032920'
を、ファイル内のすべてのレコードについて。
これは単なる間違いでした。申し訳ありませんが、私はそれを修正します。 – Colin747