Toggle navigation
Toggle navigation
This project
Loading...
Sign in
term-project
/
project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박주영
2020-11-30 23:47:52 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b5879ce7f2a40541a4451fcee06a3b050cdb437d
b5879ce7
1 parent
6dd811c2
xml => json & 리스트로 받는중
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
6 deletions
express/foodapi.js
express/foodapi.js
View file @
b5879ce
...
...
@@ -5,12 +5,15 @@ var request = require('request');
const
convert
=
require
(
'xml-js'
);
var
url
=
'http://apis.data.go.kr/1470000/FoodAdtvInfoService/getFoodAdtvInfoList'
;
var
key
=
'
PFs%2BxbmfLdZwXaK7l5l9w4xEcdaDcYByiEj9PoHq2KCPAtx%2FE1N7OPUaCPr6bam18nVQgKOnuxMlaRsJhG6gyQ
%3D%3D'
;
var
key
=
'
ofY2ppOq5kBqT5jYPaGsW%2BEy7OR5a1bf5Z9PHvqNKvwO5DSCaU2x2qCj%2FoXnuB1YVbMTlErkHWSMEsR5b7isrw
%3D%3D'
;
var
queryParams
=
'?'
+
encodeURIComponent
(
'ServiceKey'
)
+
'='
+
key
;
queryParams
+=
'&'
+
encodeURIComponent
(
'prdlst_cd'
)
+
'='
+
encodeURIComponent
(
'C0118010300000'
);
queryParams
+=
'&'
+
encodeURIComponent
(
'pc_kor_nm'
)
+
'='
+
encodeURIComponent
(
'과.채음료'
);
queryParams
+=
'&'
+
encodeURIComponent
(
'pageNo'
)
+
'='
+
encodeURIComponent
(
'1'
);
queryParams
+=
'&'
+
encodeURIComponent
(
'numOfRows'
)
+
'='
+
encodeURIComponent
(
'3'
);
//queryParams += '&' + encodeURIComponent('prdlst_cd') + '=' + encodeURIComponent('C0118010300000');
//queryParams += '&' + encodeURIComponent('pc_kor_nm') + '=' + encodeURIComponent('과.채음료');
//queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('3');
queryParams
+=
'&'
+
encodeURIComponent
(
'numOfRows'
)
+
'='
+
encodeURIComponent
(
'100'
);
global
.
foods
=
new
Array
();
request
({
url
:
url
+
queryParams
,
...
...
@@ -23,9 +26,29 @@ request({
if
(
response
.
statusCode
==
200
)
var
result
=
body
;
var
xmltojson
=
convert
.
xml2json
(
result
,{
compact
:
true
,
spaces
:
4
});
console
.
log
(
xmltojson
);
//console.log(xmltojson);
var
resObj
=
eval
(
"("
+
xmltojson
+
")"
);
for
(
var
i
=
0
;
i
<
100
;
i
++
){
function
fo
(){
foods
.
push
(
food
);
}
function
foo
(){
var
food
=
resObj
.
response
.
body
.
items
.
item
[
i
].
PC_KOR_NM
.
_text
;
fo
();
}
var
food
=
resObj
.
response
.
body
.
items
.
item
[
i
].
PC_KOR_NM
.
_text
;
global
.
foods
.
push
(
food
);
//foods.food = resObj.response.body.items.item[i].PC_KOR_NM._text;
//foods.push(resObj.response.body.items.item[i].PC_KOR_NM._text);
//console.log(resObj.response.body.items.item[i].PC_KOR_NM._text);
}
//console.log(xmltojson);
}
//console.log('Status', response.statusCode);
//console.log('Headers', JSON.stringify(response.headers));
//console.log('Reponse received', body);
console
.
log
(
foods
[
99
]);
});
console
.
log
(
foods
);
\ No newline at end of file
...
...
Please
register
or
login
to post a comment