SwiftyJSON object back to string

前端 未结 2 1677
时光说笑
时光说笑 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'
        }
    }
    
    0 讨论(0)
  • 2020-12-29 20:15

    From the README of SwiftyJSON on GitHub:

    //convert the JSON to a raw String
    if let string = libraryObject.rawString() {
    //Do something you want
      print(string)
    }
    
    0 讨论(0)
提交回复
热议问题