How to create Swift variable with JSON literal string? -
i want create string variable json string. swift doesn't seem allow me this, use ` or ' wrap json string escape it.
var json = '{"variable":"hello world"}' var json = `{"variable":"hello world"}`
thanks
swift string
literals always enclosed in double quotes "
— see here in documentation. there no alternative syntax string literals (like there in ruby example)… @ least of swift 1.2.
so if need put quotes in string literal, need escape them.
let json = "{\"variable\":\"hello world\"}"
(the other alternative if have lot of quotes escape load json string resource file example. that's not string literal anymore)
Comments
Post a Comment