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

前端 未结 4 2024
青春惊慌失措
青春惊慌失措 2021-02-15 08:05

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:33

    From Swift4 we can use JSONEncoder itself to convert Object model to Json String.

    For that we just needs to extends the Object with Codable if the json keys are standard.

    Reference :

    • https://developer.apple.com/documentation/foundation/jsonencoder
    • https://developer.apple.com/documentation/foundation/archives_and_serialization/using_json_with_custom_types

提交回复
热议问题