How to get last element of a JSON object in VBA

mantejsingh

New Member
Joined
Oct 18, 2018
Messages
1
I have the similar use case but i need to get the 1st item.

You said sMsg = Item("checkpoints")(1)("message") is returning the second message.
So what if i want 1st message?
I have tried using (0), it's returning nothing... BLANKS!
Any suggestions?

Could it be that sMsg = Item("checkpoints")(1)("message") is actually returning the second message and that you need to use:
Rich (BB code):
sMsg = Item("checkpoints")(Item.Count - 1)

to return the last message?

Regards,
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,075
I have the similar use case but i need to get the 1st item.

You said sMsg = Item("checkpoints")(1)("message") is returning the second message.
So what if i want 1st message?
I have tried using (0), it's returning nothing... BLANKS!
Any suggestions?
Look at my earlier post:
Try this:
Code:
    Dim checkpointsColl As Collection
    Set checkpointsColl = dicTrack.item(1).item("checkpoints")
    Debug.Print checkpointsColl.Count
    Debug.Print [COLOR=#ff0000][B]checkpointsColl.item(1).item("message")  'first checkpoint[/B][/COLOR]
    Debug.Print checkpointsColl.item(checkpointsColl.Count).item("message") 'last checkpoint
 

RickXL

MrExcel MVP
Joined
Sep 9, 2013
Messages
4,314
Hi Raoof,

As far as I can tell the file is shared but if you are having trouble see if you can download it from my new website.

If I said the site was "under construction" I would be exaggerating!

But the download link should work: http://www.rickxl.com
 

Forum statistics

Threads
1,086,108
Messages
5,387,880
Members
402,086
Latest member
vlmedia

Some videos you may like

This Week's Hot Topics

Top