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...
Assertions for XCTest which prevent fatal errors causing the process to die.

Hela Assertions for XCTest which prevent fatal errors causing the process to die. The following assertions are supported. These functions are built on

The easy to use Swift JSON decoder
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.

A enhanced JSON decoder.

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

A enhanced JSON decoder.

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

A common use case is wanting to convert device identifiers such as iPhone10,1 to a user friendly name; iPhone 8.

Devices Swift package that contains all devices from https://www.theiphonewiki.com/wiki/Models. A common use case is wanting to convert device identif

Simple and user-friendly application for doing the shopping list.
Simple and user-friendly application for doing the shopping list.

Shlist Simple and user-friendly application for doing the shopping list. Light _ Dark _ Features intuitive interface ability to import/export the list

Passepartout is a non-official, user-friendly OpenVPN® client for iOS and macOS.
Passepartout is a non-official, user-friendly OpenVPN® client for iOS and macOS.

Passepartout Passepartout is a non-official, user-friendly OpenVPN® client for iOS and macOS. Overview All profiles in one place Passepartout lets you

SFUserFriendlySymbols - This is user-friendly SF Symbols
SFUserFriendlySymbols - This is user-friendly SF Symbols

SFUserFriendlySymbols This is USER-FRIENDLY SF Symbols. You can use SF Symbols i

User-friendly names for HealthKit workout type cases, incl. iOS 16

HKWorkoutActivityType-Name User-friendly names for HealthKit workout type cases, incl. iOS 16 Apple's HealhKit defines workout types as enum cases, an

🗂 Never use NSSearchPathForDirectoriesInDomains again
🗂 Never use NSSearchPathForDirectoriesInDomains again

AppFolder AppFolder is a lightweight framework that lets you design a friendly, strongly-typed representation of a directories inside your app's conta

Count It, Never lose the count again
Count It, Never lose the count again

Count It Never lose the count again. Dead simple App with Apple Watch integration that lets you count anything. Laps while exercising. How many beers

An application focused on managing men's haircuts. It has never been so easy to keep the cut on time
An application focused on managing men's haircuts. It has never been so easy to keep the cut on time

An application focused on managing men's haircuts. It has never been so easy to keep the cut on time

compiler-driven, structured, type-safe source generation. never use gyb again!

factory 2022-09-10-a factory is a structured, type-safe source generation tool. It is intended to be a replacement for (and improvement over) the gyb

A Swift Encoder for encoding any Encodable value into an array of URLQueryItem.

URLQueryItemEncoder A Swift Encoder for encoding any Encodable value into an array of URLQueryItem. As part of the SE-0166, Swift has a foundation for

Rudimentary implementation of a uncompressed PNG encoder in Swift without any dependencies

MicroPNG This package currently offers a very minimal PNG encoder for uncompressed RGB and RGBA PNG files. It does not rely on any frameworks and shou

Reflection, Dict2Model, Model2Dict, Archive
Reflection, Dict2Model, Model2Dict, Archive

感谢小饭的翻译 中文文档 ###Selfless pay, just to make you faster to conquer swift! .Reflection .convert dictionary to model .convert model to dictionary .convert

Reflection for enumerations in Objective-C.

ReflectableEnum A macro and a set of functions introducing reflection for enumerations in Objective-C. Features: get a string value for an enumeration

URL query encoder with OpenAPI serialization options support

URLQueryEncoder A customizable Swift Encoder that encodes instances of data type

OpenFocusTimer - Pomodoro timer with categories, reflection, history & statistics

OpenFocusTimer Pomodoro timer with categories, reflection, history & statistics.

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
Reflection, Dict2Model, Model2Dict, Archive

感谢小饭的翻译 中文文档 ###Selfless pay, just to make you faster to conquer swift! .Reflection .convert dictionary to model .convert model to dictionary .convert

时点软件冯成林 307 Nov 22, 2022
Auto reflection tool from JSON to Model, user friendly JSON encoder / decoder, aims to never die

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 imp

John Lui 454 Oct 30, 2022
PMJSON provides a pure-Swift strongly-typed JSON encoder/decoder

Now Archived and Forked PMJSON will not be maintained in this repository going forward. Please use, create issues on, and make PRs to the fork of PMJS

Postmates Inc. 364 Sep 28, 2022
iCalSwift - iCalendar(RFC 5545) encoder and decoder for Swift

iCalSwift - iCalendar(RFC 5545) encoder and decoder for Swift

Jichan Park 6 Sep 1, 2022
DevTool - A simple UI and powerful Mac OS application, Such as JSON-Formatting tool, JSON-to-model tool, AppIcon generator, Network-Request tool...

?? ?? ?? A simple UI and powerful Mac OS application. It is a collection of tools commonly used in my development work. Such as JSON-Formatting tool, JSON-to-model tool, AppIcon generator, Network-Request tool...

渠晓友 3 Dec 21, 2022
A video decoder built on ffmpeg which allows libpag to use ffmpeg as its software decoder for h264 decoding.

ffavc ffavc is a video decoder built on ffmpeg which allows libpag to use ffmpeg as its software decoder for h264 decoding. Build ffmpeg First, make s

Portable Animated Graphics 8 Nov 24, 2022
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 Jan 3, 2023
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 964 Dec 14, 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 964 Dec 14, 2022