박주영

xml => json & 리스트로 받는중

...@@ -5,12 +5,15 @@ var request = require('request'); ...@@ -5,12 +5,15 @@ var request = require('request');
5 const convert = require('xml-js'); 5 const convert = require('xml-js');
6 6
7 var url = 'http://apis.data.go.kr/1470000/FoodAdtvInfoService/getFoodAdtvInfoList'; 7 var url = 'http://apis.data.go.kr/1470000/FoodAdtvInfoService/getFoodAdtvInfoList';
8 -var key ='PFs%2BxbmfLdZwXaK7l5l9w4xEcdaDcYByiEj9PoHq2KCPAtx%2FE1N7OPUaCPr6bam18nVQgKOnuxMlaRsJhG6gyQ%3D%3D'; 8 +var key ='ofY2ppOq5kBqT5jYPaGsW%2BEy7OR5a1bf5Z9PHvqNKvwO5DSCaU2x2qCj%2FoXnuB1YVbMTlErkHWSMEsR5b7isrw%3D%3D';
9 var queryParams = '?' + encodeURIComponent('ServiceKey') + '=' +key; 9 var queryParams = '?' + encodeURIComponent('ServiceKey') + '=' +key;
10 -queryParams += '&' + encodeURIComponent('prdlst_cd') + '=' + encodeURIComponent('C0118010300000'); 10 +//queryParams += '&' + encodeURIComponent('prdlst_cd') + '=' + encodeURIComponent('C0118010300000');
11 -queryParams += '&' + encodeURIComponent('pc_kor_nm') + '=' + encodeURIComponent('과.채음료'); 11 +//queryParams += '&' + encodeURIComponent('pc_kor_nm') + '=' + encodeURIComponent('과.채음료');
12 -queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); 12 +//queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('3');
13 -queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('3'); 13 +queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('100');
14 +
15 +global.foods = new Array();
16 +
14 17
15 request({ 18 request({
16 url: url + queryParams, 19 url: url + queryParams,
...@@ -23,9 +26,29 @@ request({ ...@@ -23,9 +26,29 @@ request({
23 if(response.statusCode ==200) 26 if(response.statusCode ==200)
24 var result =body; 27 var result =body;
25 var xmltojson = convert.xml2json(result,{compact:true,spaces:4}); 28 var xmltojson = convert.xml2json(result,{compact:true,spaces:4});
26 - console.log(xmltojson); 29 + //console.log(xmltojson);
30 + var resObj = eval("("+xmltojson+")");
31 +
32 + for(var i=0;i<100;i++){
33 + function fo(){
34 + foods.push(food);
35 + }
36 + function foo(){
37 + var food =resObj.response.body.items.item[i].PC_KOR_NM._text;
38 + fo();
39 + }
40 + var food = resObj.response.body.items.item[i].PC_KOR_NM._text;
41 + global.foods.push(food);
42 + //foods.food = resObj.response.body.items.item[i].PC_KOR_NM._text;
43 + //foods.push(resObj.response.body.items.item[i].PC_KOR_NM._text);
44 + //console.log(resObj.response.body.items.item[i].PC_KOR_NM._text);
45 + }
46 + //console.log(xmltojson);
27 } 47 }
28 //console.log('Status', response.statusCode); 48 //console.log('Status', response.statusCode);
29 //console.log('Headers', JSON.stringify(response.headers)); 49 //console.log('Headers', JSON.stringify(response.headers));
30 //console.log('Reponse received', body); 50 //console.log('Reponse received', body);
31 -});
...\ No newline at end of file ...\ No newline at end of file
51 + console.log(foods[99]);
52 +});
53 +
54 +console.log(foods);
...\ No newline at end of file ...\ No newline at end of file
......