swift - SwiftyJSON Parse JSON error for array object -


i retrieving data url this:

let url = nsurl(string: baseurl)         let request = nsurlrequest(url: url!)         let session = nsurlsession(configuration: nsurlsessionconfiguration.defaultsessionconfiguration())         let task = session.datataskwithrequest(request) { (data, response, error) -> void in             if error == nil {                 let swiftyjson = json(data: data!)                 let results = swiftyjson[0]["name"]                 print(results)             } else {                 print("error")             }         } 

for above, data this:

[      {         "_id":"123",       "_rev":"345",       "name":"hey"    },    {         "_id":"133",       "_rev":"33345",       "name":"hello"    } ] 

i end in error block , not sure why?

i pasted json in chrome console , able swiftyjson[0].name. print elements above json object.

error:

error optional(error domain=nsurlerrordomain code=-1003 "a server specified hostname not found." userinfo={nsunderlyingerror=0x7f87514ab570 {error domain=kcferrordomaincfnetwork code=-1003 "(null)" userinfo={_kcfstreamerrorcodekey=8, _kcfstreamerrordomainkey=12}}, nserrorfailingurlstringkey=http://localhost:3000/idea, nserrorfailingurlkey=http://localhost:3000/idea, _kcfstreamerrordomainkey=12, _kcfstreamerrorcodekey=8, nslocalizeddescription=a server specified hostname not found.}) 

please note, localhost:3000 on.

the error pasted may request's hostname not found. "a server specified hostname not found." json parse seems right totally.


Comments

Popular posts from this blog

PHP while loop dynamic rowspan -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

Spring Boot + JPA + Hibernate: Unable to locate persister -