簡體   English   中英

如何在Nodejs中從json對象數組轉換為String?

[英]How to convert from array of json object to String in Nodejs?

我從HTTP post獲得響應作為json對象的數組。 但想要顯示為字符串。 請看我的回復..

{ total: 14,
  results:
   [ { name: [Object],
       comments: [],
       attributes: [Object],
       type: [Object],
       context: [Object],
       status: 'Accepted',
       score: 1.7646775,
       modified: 1426085315767,
       parents: [] },
     { name: [Object],
       comments: [],
       attributes: [Object],
       type: [Object],
       context: [Object],
       status: 'Accepted',
       score: 1.3945999,
       modified: 1425386916807,
       parents: [] },

下面的代碼顯示響應。

function(error, response, data){
    if(error) {
        console.log(error);
    } else {
          console.log(data);

}

NodeJS有ES5 JSON類,里面有stringify()方法

function(error, response, data){
    if(error) {
      console.log(error);
    } else {
      console.log(JSON.stringify(data));
}

JSON.stringify

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM