Forum Discussion

HimanshuTayal's avatar
HimanshuTayal
Community Hero
6 years ago
Solved

how to determine whether json is jsonArray or jsonObject

Hi All,   I am currently stucked at a point where i need to check whether the given json contains array or not.   Can any one help me on this:   Suppose below is my json:   { "statu...
  • HimanshuTayal's avatar
    HimanshuTayal
    6 years ago

    Hi nmrao ,

     

    Thanks for the reply, i will check mentioned solution, however i have done this with below code

     

     

    boolean isCollectionOrArray(object) {    
        [Collection, Object[]].any { it.isAssignableFrom(object.getClass()) }
    }
    
    // some tests
    assert isCollectionOrArray([])

     

    For this i imported below library:

     

    import java.lang.Object;