从JSON数组获取干净的消息

时间:2019-01-28 17:40:13

标签: node.js

`

const Discord = require('discord.js')                                                                                                                                                                     
const db = require('quick.db')                                                                                                                                                                            
exports.run = (client, message, args) => {                                                                                                                                                                

let pointiz = JSON.stringify(db.all(10))                                                                                                                                                                  
message.channel.send(pointiz)                                                                                                                                                                             


}                                                                                                                                                                                                         

exports.conf = {                                                                                                                                                                                          
  enabled: true,                                                                                                                                                                                          
  guildOnly: false,                                                                                                                                                                                       
  aliases: ["stats"],                                                                                                                                                                                     
  permLevel: 1                                                                                                                                                                                            
};                                                                                                                                                                                                        

exports.help = {                                                                                                                                                                                          
  name: 'lead',                                                                                                                                                                                           
  description: 'Text.',                                                                                                                                                               
  usage: 'text'                                                                                                                                                                                       
};    `     

我想做的是将干净的消息发送到排行榜,我不知道如何翻译这些字符串。

消息: [{"ID":"Usur","data":{"points":200}},{"ID":"points","data":0},{"ID":"Usur-427258453501673484","data":{"points":0}},{"ID":"Usur427258453501673484","data":{"points":0}},{"ID":"Usur-484607136345751564","data":{"points":0}},{"ID":"427258453501673484","data":{"points":0}},{"ID":"Usur-198504055885004800","data":{"points":0}},{"ID":"198504055885004800","data":{"points":10}}]

2 个答案:

答案 0 :(得分:1)

好吧,您得到的显然是一组对象。要访问其元素,您需要做类似pointiz[ i ].field .....的事情,显然不是JSON.stringification它。问题是太笼统了。

答案 1 :(得分:1)

在这里,请看@此示例:

let results = [{"ID":"Usur","data":{"points":200}},{"ID":"points","data":0},{"ID":"Usur-427258453501673484","data":{"points":0}},{"ID":"Usur427258453501673484","data":{"points":0}},{"ID":"Usur-484607136345751564","data":{"points":0}},{"ID":"427258453501673484","data":{"points":0}},{"ID":"Usur-198504055885004800","data":{"points":0}},{"ID":"198504055885004800","data":{"points":10}}];

// PRINT HOW YOU WISH INSIDE THE forEach LOOP
results.forEach( x => console.log( x ) );