admin管理员组文章数量:1384579
I'm getting response from HTTP post as array of json objects. but want to display as string. Please see my response..
{ total: 14,
results:
[ { name: [Object],
ments: [],
attributes: [Object],
type: [Object],
context: [Object],
status: 'Accepted',
score: 1.7646775,
modified: 1426085315767,
parents: [] },
{ name: [Object],
ments: [],
attributes: [Object],
type: [Object],
context: [Object],
status: 'Accepted',
score: 1.3945999,
modified: 1425386916807,
parents: [] },
Below code to display response.
function(error, response, data){
if(error) {
console.log(error);
} else {
console.log(data);
}
I'm getting response from HTTP post as array of json objects. but want to display as string. Please see my response..
{ total: 14,
results:
[ { name: [Object],
ments: [],
attributes: [Object],
type: [Object],
context: [Object],
status: 'Accepted',
score: 1.7646775,
modified: 1426085315767,
parents: [] },
{ name: [Object],
ments: [],
attributes: [Object],
type: [Object],
context: [Object],
status: 'Accepted',
score: 1.3945999,
modified: 1425386916807,
parents: [] },
Below code to display response.
function(error, response, data){
if(error) {
console.log(error);
} else {
console.log(data);
}
Share
Improve this question
asked Nov 15, 2016 at 20:18
user2848031user2848031
22713 gold badges38 silver badges73 bronze badges
2
-
4
Can you just use
console.log(JSON.stringify(data))
? – Travis J Commented Nov 15, 2016 at 20:19 -
You can do that with map:
const arrAsStr = arr.map( (r) => JSON.stringify(r) );
– Hosar Commented Nov 15, 2016 at 21:50
1 Answer
Reset to default 4NodeJS has ES5 JSON
class which has stringify()
method in it
function(error, response, data){
if(error) {
console.log(error);
} else {
console.log(JSON.stringify(data));
}
JSON.stringify
本文标签: javascriptHow to convert from array of json object to String in NodejsStack Overflow
版权声明:本文标题:javascript - How to convert from array of json object to String in Nodejs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744537974a2611430.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论