1

I'm trying to serialize json object like this

let jsonObject: [String: Any] = [
        "Description":problemDescription.text!,
        "Photo": byteArray
    ]
let jsonData = try! NSJSONSerialization.dataWithJSONObject(jsonObject, options: .PrettyPrinted)

but I'm getting this type of error:

swift 2 argument type string any does not conform to expected type any object.

Any ideas?

vadian
  • 274,689
  • 30
  • 353
  • 361
markan3
  • 117
  • 2
  • 9
  • 1
    JSON supports only string, number (Int, double, bool) and . Your code is Swift 2, but `[String:Any]` as JSON dictionary belongs to Swift 3. And don't send pretty printed JSON. The server doesn't care. – vadian Dec 21 '16 at 15:52
  • is the server expecting the photo data to be Base64 encoded? – Michael Dautermann Dec 22 '16 at 00:08
  • @ Michael Dautermann - yes, the server needs base64 string converted to byte array – markan3 Dec 22 '16 at 06:54
  • @vadian - I have tried [String: AnyObject] but without success – markan3 Dec 22 '16 at 06:54
  • The problem is `byteArray`. Make sure that it contains only the supported types. – vadian Dec 22 '16 at 08:02
  • @vadian - do you suggest that I try to convert bytearray into NSString or NSArray? – markan3 Dec 22 '16 at 08:16
  • It is not clear what `byteArray` is. `NSData` or C-Array or what? – vadian Dec 22 '16 at 08:23
  • I'm trying to upload image to server along with other data in json format. The server accepts image in []byte format. So my idea was to first convert image to base64 string which I would then convert to byte[]. – markan3 Dec 22 '16 at 08:28

1 Answers1

0

update: It seems that when I'm printing json object after this line

let jsonData = try! NSJSONSerialization.dataWithJSONObject(jsonObject, options: .PrettyPrinted)

that that conversion to byte[] occurs itself. At least seems that way in console debug.

markan3
  • 117
  • 2
  • 9