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

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

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

asp.net mvc - breakpoint on javascript in CSHTML? -