JSONNeverDie - Auto reflection tool from JSON to Model, user friendly JSON encoder / decoder, aims to never die

Overview

JSONNeverDie is an auto reflection tool from JSON to Model, a user friendly JSON encoder / decoder, aims to never die. Also JSONNeverDie is a very important part of Pitaya.

中文介绍

Example

set up a Model:

class People: JSONNDModel {
    @objc var name = ""
}

reflex JSON to Model automatic:

let json = JSONND(string: "{\"name\": \"JohnLui\"}")
let people = People(JSONNDObject: json)
print(people.name)

Features

reflection features

  • JSON to Model reflection automatic
  • auto reflection with no need of init()
  • supports multi-level reflection

Read the documentation of auto reflection.

JSON encode / decode features

  • supports all types: Int, Double, Bool, String, Array
  • user friendly: Xcode can prompt all available types
  • provides both Optional-type(Int?) and Original-type(Int)

And JSONNeverDie is well tested.

Requirements

  • iOS 7.0+
  • Swift 4 (Version 3) in current swift4 branch
  • Swift 3 (Version 2) in swift3 branch
  • Swift 2.x / Xcode 7 (Version 1.x) in master branch

##Contribution

You are welcome to fork and submit pull requests.

##License

JSONNeverDie is open-sourced software licensed under the MIT license.

中文介绍

基本示例

构建一个 Model:

class People: JSONNDModel {
    @objc var name = ""
}

从字符串转换成 JSON 再自动映射为 Model:

let json = JSONND(string: "{\"name\": \"JohnLui\"}")
let people = People(JSONNDObject: json)
print(people.name)

中文文档

参与开源

欢迎提交 issue 和 PR,大门永远向所有人敞开。

开源协议

本项目遵循 MIT 协议开源,具体请查看根目录下的 LICENSE 文件。

You might also like...
Mappable - Flexible JSON to Model converter, specially optimized for immutable properties

Mappable is a lightweight, flexible, easy-to-use framework to convert JSON to model, specially optimized for immutable property initializatio

🌟 Super light and easy automatic JSON to model mapper

magic-mapper-swift 🌟 Super light and easy automatic JSON to model mapper Finish writing README.md Ability to map NSManagedObject Ability to convert m

CryptoWatch is an application to fetch the currency datas from an api and show their updated values to user. User is able to get the coin datas without an extra effort.
CryptoWatch is an application to fetch the currency datas from an api and show their updated values to user. User is able to get the coin datas without an extra effort.

CryptoTracker In order to combine my work and studies, I made a small project that keeps the user's registration datas in memory, checks them when nee

A tool for fast serializing & deserializing of JSON
A tool for fast serializing & deserializing of JSON

FastEasyMapping Overview Requirements Installation CocoaPods Carthage Usage Deserialization Serialization Mapping Attributes Relationships Assignment

JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift.

JSEN /ˈdʒeɪsən/ JAY-sən JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift. A JSON, as defined in the EC

JSON-Practice - JSON Practice With Swift

JSON Practice Vista creada con: Programmatic + AutoLayout Breve explicación de l

Ss-json - High-performance json parsing in swift

json 0.1.1 swift-json is a pure-Swift JSON parsing library designed for high-per

Swift-json - High-performance json parsing in swift

json 0.1.4 swift-json is a pure-Swift JSON parsing library designed for high-per

Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON.

JSONFeed Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON. For more information about this new feed format visit: https:/

Comments
  • 个人觉得在处理JSON转Model的时候,由Model提供一个Map更好一些

    个人觉得在处理JSON转Model的时候,由Model提供一个Map更好一些

    Hello,johnlui: JSONNeverDie在处理JSON转Model的时候,是通过Mirror映射获得对象的属性,然后通过属性名的获取JSON中对应的数据,赋值给对象。这样的话属性名和JSON必须一一对应。假设出现下面的情况付出的代价就比较大:

    //一开始服务端提供的数据格式
    {“string”: "json", "float": 1.0, "int": 1}
    
    class TestModel: JSONNDModel {
        var string = ""
        var float: Float = 0.0
        var int = 0
    }
    

    这样处理没什么问题,然后在n各文件中调用了m次

    let testModel = TestModel((JSONNDObject: json)
    testModel.string
    testModel.float
    testModel.int
    

    突然有一天服务端因为需求的变化,不得不将string的字段换成char,那我必须修改成

    class TestModel: JSONNDModel {
        var char = ""
        var float: Float = 0.0
        var int = 0
    }
    

    并且要将项目中所有的testModel.string换成testModel.char,这样付出的代价比较大了。

    所以我觉得可以让Mode提供一个l可选Map,用于映射,如果有Map按照Map映射处理。没有提供Map则按照Mirror的方式映射

    opened by tailang 3
  • Test coverage is only 54 %

    Test coverage is only 54 %

    You can see that when you go to 'manage scheme', test, 'gather coverage data' and then run your test. then go to 'report navigate', test, coverage. You will also see what's not covered in your code

    opened by evermeer 1
  • Support protocol init

    Support protocol init

    Hey, nice library. It would by nice if it also supported protocols (with implementation) instead of just subclassing. Some other libraries, mainly ORMs need subclassing and it would be impossible to use this and Realm for example, or even SharkORM, at the same time.

    opened by Xioshock 1
  • 改了Model属性值再取JSON字符串不行?

    改了Model属性值再取JSON字符串不行?

    let json = JSONND(dictionary: dic!) let u = UserInfo(JSONNDObject: son)

    u.age = 22

    print(u.RAW)

    此时age的值还是之前的18,并没有改为22

    难道做不到这样的转换? Json字符串 -> JSONModel -> 操作model -> Json字符串

    opened by wdrabbit 1
Releases(v2.0.2)
Owner
John Lui
John Lui
A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.

MJExtension A fast, convenient and nonintrusive conversion framework between JSON and model. 转换速度快、使用简单方便的字典转模型框架 ?? ✍??Release Notes: more details Co

M了个J 8.5k Nov 15, 2022
Dogtector: dog breed detection app for iOS using YOLOv5 model combined with Metal based object decoder optimized

Dogtector Project description Dogtector is dog breed detection app for iOS using YOLOv5 model combined with Metal based object decoder optimized for u

Bartłomiej Pluta 21 Aug 1, 2022
Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift

EVReflection General information At this moment the master branch is tested with Swift 4.2 and 5.0 beta If you want to continue using EVReflection in

Edwin Vermeer 963 Nov 19, 2022
The easy to use Swift JSON decoder

Unbox is deprecated in favor of Swift’s built-in Codable API and the Codextended project. All current users are highly encouraged to migrate to Codable as soon as possible.

John Sundell 2k Nov 8, 2022
A enhanced JSON decoder.

JSONDecoderEx A enhanced JSON decoder. Usage struct User: Codable { struct Role: OptionSet, Codable, CustomStringConvertible { let rawValu

SAGESSE-CN 106 Oct 19, 2022
A enhanced JSON decoder.

JSONDecoderEx A enhanced JSON decoder. Usage struct User: Codable { struct Role: OptionSet, Codable, CustomStringConvertible { let rawValu

SAGESSE-CN 106 Oct 19, 2022
SwiftyJSON decoder for Codable

SwiftyJSONDecoder 功能 继承自 JSONDecoder,在标准库源码基础上做了改动,与其主要区别如下 使用 SwiftyJSON 解析数据,使用其类型兼容功能 废弃 nonConformingFloatDecodingStrategy 属性设置,Double 及 Float 默认解

null 2 Aug 10, 2022
HandyJSON is a framework written in Swift which to make converting model objects to and from JSON easy on iOS.

HandyJSON To deal with crash on iOS 14 beta4 please try version 5.0.3-beta HandyJSON is a framework written in Swift which to make converting model ob

Alibaba 4k Nov 14, 2022
ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects to and from JSON.

ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects (classes and structs) to and from J

Tristan Himmelman 9k Nov 20, 2022
JSONExport is a desktop application for Mac OS X which enables you to export JSON objects as model classes with their associated constructors, utility methods, setters and getters in your favorite language.

JSONExport JSONExport is a desktop application for Mac OS X written in Swift. Using JSONExport you will be able to: Convert any valid JSON object to a

Ahmed Ali 4.7k Nov 22, 2022