Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftyJSON - is possible to check object type?

For example I have a json

var json = JSON(data: data!)

inside it I reference to object

var list = json["OBJECT"]

is there a way, that I can check if it is an object, or array, or string and return bool ?

This doesnt help. var list will always be type of JSON. And I want to find a way to check what is inside.

like image 583
Alexey K Avatar asked Dec 05 '22 18:12

Alexey K


1 Answers

The JSON objects in SwiftyJSON have a type property whose type is an enum

public enum Type: Int {
    case number
    case string
    case bool
    case array
    case dictionary
    case null
    case unknown
}

For example

var list = json["OBJECT"]
switch list.type {
  case .array: print("list is Array")
  case .dictionary: print("list is Dictionary")
  default: break
}
like image 122
vadian Avatar answered Dec 28 '22 19:12

vadian