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
Post a Comment