Is SwiftyJson capable of converting a custom swift class to a json string?

前端 未结 4 1063
不思量自难忘°
不思量自难忘° 2021-02-15 08:11

Given below is my custom swift class. My Question is how to convert an object of this class to a json string using SwiftyJson?

class Equipment{

    var UniqueI         


        
4条回答
  •  余生分开走
    2021-02-15 08:43

    UPDATE

    OP is now happy with EVReflection. So I assume that at this moment it's the best choice.

    ORIGINAL ANSWER

    Since Swift reflection possibilities is not yet such rich there is no ultimate solution now like google-gson for Java.

    Libraries like SwiftJSON and Swift ObjectMapper are just sugared NSJSONSerialization and require you to define mappings from json fields to object properties.

    But things are changing and you can try out JsonSerializerSwift. I have not yet used it but it use Swift reflection and seems to work fine.

    Also check out Swift Mirrors and JSON by Chris Eidhof article. It explains how JSON serialization using reflection possibilities works.

提交回复
热议问题