ios - How to convert a string into JSON using SwiftyJSON -


the string convert:

[{"description": "hi","id":2,"img":"hi.png"},{"description": "pet","id":10,"img":"pet.png"},{"description": "hello! :d","id":12,"img":"hello.png"}]

the code convert string:

var json = json(stringliteral: stringjson)

the string converted json , when try count how many blocks inside json (expected answer = 3), 0.

print(json.count)

console output: 0

what missing? appreciated.

actually, there built-in function in swifyjson called parse

/**  create json json string - parameter string: normal json string '{"a":"b"}'  - returns: created json */ public static func parse(string:string) -> json {     return string.datausingencoding(nsutf8stringencoding)         .flatmap({json(data: $0)}) ?? json(nsnull()) } 

var json = json.parse(stringjson)

its changed

var json = json.init(parsestring:stringjson)


Comments

Popular posts from this blog

php - Passing multiple values in a url using checkbox -

compilation - PHP install fails on Ubuntu 14 (make: *** [sapi/cli/php] Error 1) PHP 5.6.20 -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -