xcode - Swift/Cocoa json parse error? -


new swift/iphone dev ...

if have string in json array of objs, can start bracket '['. according json spec, afaik, okay. however, following blows unit test in swift/xcode:

var json = "[{\"class\":\"productdesign\"},{\"class\":\"productdesign\"}]" let jsonobject : anyobject! = nsjsonserialization.jsonobjectwithdata(json.datausingencoding(nsutf8stringencoding), options: nsjsonreadingoptions.mutablecontainers, error: nil) nsdictionary 

i've seen blog write-ups of people doing not work me (xcode funny stuff, popping :

0x287784:  je     0x28778d                  ; swift_dynamiccastobjcclassunconditional + 61 0x287786:  addl   $0x10, %esp 0x287789:  popl   %esi 0x28778a:  popl   %edi 0x28778b:  popl   %ebp 0x28778c:  retl    0x28778d:  leal   0xea35(%esi), %eax 0x287793:  movl   0x468ef(%esi), %ecx 0x287799:  movl   %eax, 0x8(%ecx) 0x28779c:  movl   $0x0, 0xc(%ecx) 0x2877a3:  int3    0x2877a4:  nopw   %cs:(%eax,%eax) 

any ideas? bug in release?? programmer stupidity?

your json array, you're casting result of nsjsonserialization.jsonobjectwithdata nsdictionary; cast nsarray instead:

let jsonobject : anyobject! = nsjsonserialization.jsonobjectwithdata(json.datausingencoding(nsutf8stringencoding), options: nsjsonreadingoptions.mutablecontainers, error: nil) nsarray 

note: you can exclude anyobject! type declaration , do:

let jsonobject = nsjsonserialization.jsonobjectwithdata(json.datausingencoding(nsutf8stringencoding), options: nsjsonreadingoptions.mutablecontainers, error: nil) nsarray 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -