prine/ROJSONParser

crash on null fields

Closed this issue · 2 comments

I added a function to class Value<T> to set a default value

class func get(rojsonobject:ROJSONObject, key:String, defaultValue:T) -> T {
    if rojsonobject.getJSONValue(key) == nil {
        return defaultValue
    } else {
        return self.get(rojsonobject, key: key)
    }
}

Thanks @eskizyen

I have also implemented something quite similar but unfortunately I didn't integrate it in the current commit on github. I'm going to merge your solution with my internal solution for dealing with null values. I was thinking about a more dynamic implementation where it does automatically set the T() as default value. Need to check this later.

I was thinking the same solution but i couldn't figure it out. going to try it when i have time. And thanks for the library, good job.