Results 1 to 2 of 2

Thread: Check if Object exists in Collection

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2018
    Posts
    2

    Check if Object exists in Collection

    I've created my own JSON parser in VB6. Feed it a string, it returns an Object that is a collection of the next level of Objects, each of which is a collection of the next level, etc. Normally I am accessing it with For Each x in Collection. But I need to know if a certain member exists before I bother with looping the rest of that collection. I want to test for existence with something like this:

    Code:
    If Not Role("Abilities")("PriorityOverride") Is Nothing Then
    But that way of dereferencing is not working. Each layer is simply generic Object, not any specific object. If that isn't clear just ask and I'll try and make it clearer. Thanks!

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Check if Object exists in Collection

    One potential trap for new players is that while Collection keys are case-insensitive this isn't true of JSON.

    You could consider my JSONBag in the CodeBank or any of several other implementations that have a few miles on them to help weed out this and other problems.


    But to answer your question directly... if you need an "exists" test for a Collection the most obvious route is exception handling.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width