I am trying to convert a simple struct to JSON string. The struct looks like this:
struct MyStruct: Equatable {
let propertyA:Int
let propertyB:String
let propertyC:Double
//There are about ten more fields
func myStructMethod->String{
return "return value"
}
}
So, because the struct doesn't conform to AnyObject
type (but rather to Any
I guess) the simple conversion like this fails:
let data = try NSJSONSerialization.dataWithJSONObject(myStructArray, options: nil)
let string = NSString(data: data!, encoding: NSUTF8StringEncoding)
Is there some way to skip creating JSON string "by the hand" (say using array map and building string by myself)?