Nested JSON types crash printing
ncalexan opened this issue · comments
This surprised me:
let inner: JSON = JSON([:])
let outer: JSON = JSON(["inner":inner])
outer.toString() // Crashes!
I expected this to be equivalent to having outer: Dictionary<String, AnyObject>
. Am I confused? Is this an unreasonable expectation?
@dankogai any word on why this happens or what could be done? asDictionary: [String:JSON]?
very carefully wraps value types in JSON
to preserve the access interface so I doubt we'd want to make asDictionary: [String:AnyObject]?
.
Thank you. Fixed in fd5ae63 .
The reason is that JSON
itself not NSObject
which can directory be passed to NSJSONSerialization.dataWithJSONObject()
. And making JSON
NSObject
is not a good idea since it is a Swift object. Instead of inheriting JSON
I wrote a couple of extra .init()
's that when it is either an arrary or dictionary of JSON, it unwraps the object.
Dan the Maintainer Thereof