SwiftyJSON object back to string

前端 未结 2 1692
时光说笑
时光说笑 2020-12-29 19:51

I\'m using the SwiftyJSON library to parse JSON into swift objects. I can create the JSON object and read and write to it

// Create json object to represent          


        
2条回答
  •  爱一瞬间的悲伤
    2020-12-29 20:09

    //convert the JSON to a raw String
    if let strJson = jsonObject.rawString() {
        // 'strJson' contains string version of 'jsonObject'
    }
    
    //convert the String back to JSON (used this way when used with Alamofire to prevent errors like Task .<1> HTTP load failed (error code: -1009 [1:50])
    if let data = strJson.data(using: .utf8) {
        if let jsonObject = try? JSON(data: data) {
            // 'jsonObject' contains Json version of 'strJson'
        }
    }
    

提交回复
热议问题