How to get last element of a JSON object in VBA
Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: How to get last element of a JSON object in VBA
Thanks Thanks: 0 Likes Likes: 0

  1. #11
    Board Regular
    Join Date
    Aug 2015
    Posts
    117
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to get last element of a JSON object in VBA

    Quote Originally Posted by John_w View Post
    Code:
    Dim trackingsColl As Collection
    and replace instances of dicTrack with trackingsColl.
    Ok got it, great! Thanks a lot!

  2. #12
    New Member
    Join Date
    Oct 2018
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to get last element of a JSON object in VBA

    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?

    Quote Originally Posted by RickXL View Post
    Could it be that sMsg = Item("checkpoints")(1)("message") is actually returning the second message and that you need to use:
    Code:
    sMsg = Item("checkpoints")(Item.Count - 1)
    

    to return the last message?

    Regards,

  3. #13
    Board Regular
    Join Date
    Oct 2007
    Posts
    5,807
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    2 Thread(s)

    Default Re: How to get last element of a JSON object in VBA

    Quote Originally Posted by mantejsingh View Post
    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:
    Quote Originally Posted by John_w View Post
    Try this:
    Code:
        Dim checkpointsColl As Collection
        Set checkpointsColl = dicTrack.item(1).item("checkpoints")
        Debug.Print checkpointsColl.Count
        Debug.Print checkpointsColl.item(1).item("message")  'first checkpoint
        Debug.Print checkpointsColl.item(checkpointsColl.Count).item("message") 'last checkpoint

  4. #14
    New Member
    Join Date
    Aug 2019
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to get last element of a JSON object in VBA

    Dear Rick

    Would you please share the file on the Taylor diagram in excel which you provided for the following question in the following link?
    raoofmostafazadeh@uma.ac.ir

    https://www.mrexcel.com/forum/excel-...ams-excel.html

    Thanks in advanced.
    Regards


  5. #15
    MrExcel MVP RickXL's Avatar
    Join Date
    Sep 2013
    Location
    UK North Midlands
    Posts
    4,314
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)

    Default Re: How to get last element of a JSON object in VBA

    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
    RickXL

    Excel 2013 and Windows 10

  6. #16
    New Member
    Join Date
    Aug 2019
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to get last element of a JSON object in VBA

    Thanks. That was GREAT

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •