M
M
Maxim Recipient2019-09-06 19:16:29
JavaScript
Maxim Recipient, 2019-09-06 19:16:29

How to extract three JSON branches?

Hello. Small question:
I have this JSON response:

{
"response": {
"count": 398,
"items": [{
"id": 1680163,
"body": "test message",
"user_id": 2314852,
"from_id": 2314852,
"date": 1468343751,
"read_state": 1,
"out": 0
}],
"in_read": 1680163,
"out_read": 1680162
}
}

I can easily get a value from it, countetc., but there are small problems:
I want to extract the value id, but when I try, an error occurs or undefined, below are examples of my extractions:
1) - retrieves and sends the value perfectly. 2) - does not extract and sends .message.send(`${response.count}`);
message.send(`${response.items.id}`);undefined
WHOLE PIECE OF CODE

cmd.hear(/^(?:бс инфо)$/i, async (message, bot) => { 

    if(!message.isChat) return bot(`команда работает только в беседе!`);
await vk.api.messages.getConversationMembers({
  offset: 0,
  count: 1,
    peer_id: message.peerId,
  start_message_id: 0,
  group_id: 184895474
}).then((response) => {

message.send(`${response.items["body"]}`);
});
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2019-09-06
@ms_toster

response.items[0].id
you have items - an array that already contains an object with an id field

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question