I know there is a question with same title here. But in that question, he is trying to convert a dictionary into JSON. But I have a simple sting like this: "garden"
And I have to send it as JSON. I have tried SwiftyJSON but still I am unable to convert this into JSON.
Here is my code:
func jsonStringFromString(str:NSString)->NSString{
let strData = str.dataUsingEncoding(NSUTF8StringEncoding)
let json = JSON(data: strData!)
let jsonString = json.string
return jsonString!
}
My code crashes at the last line:
fatal error: unexpectedly found nil while unwrapping an Optional value
Am I doing something wrong?