Skip to content

Files

Latest commit

author
chantu.lhl
Jul 27, 2021
6414e41 · Jul 27, 2021

History

History
697 lines (500 loc) · 19.1 KB

README.md

File metadata and controls

697 lines (500 loc) · 19.1 KB
xuyecancijianzywongzigiiswwlqwlynnleelhlkhasinskiiosdevzonecodetalks-new
Sep 20, 2016
Sep 20, 2016
1
# HandyJSON
2
Jul 27, 2021
Jul 27, 2021
3
***To deal with crash on iOS 15 beta3 please try version 5.0.4-beta***
Aug 5, 2020
Aug 5, 2020
4
Jan 8, 2017
Jan 8, 2017
5
HandyJSON is a framework written in Swift which to make converting model objects( **pure classes/structs** ) to and from JSON easy on iOS.
Sep 27, 2016
Sep 27, 2016
6
Sep 11, 2017
Sep 11, 2017
7
Compared with others, the most significant feature of HandyJSON is that it does not require the objects inherit from NSObject(**not using KVC but reflection**), neither implements a 'mapping' function(**writing value to memory directly to achieve property assignment**).
Sep 20, 2016
Sep 20, 2016
8
Sep 20, 2017
Sep 20, 2017
9
HandyJSON is totally depend on the memory layout rules infered from Swift runtime code. We are watching it and will follow every bit if it changes.
Nov 19, 2016
Nov 19, 2016
10
Sep 26, 2016
Sep 26, 2016
11
[![Build Status](https://travis-ci.org/alibaba/HandyJSON.svg?branch=master)](https://travis-ci.org/alibaba/HandyJSON)
Oct 5, 2016
Oct 5, 2016
12
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
Sep 26, 2016
Sep 26, 2016
13
[![Cocoapods Version](https://img.shields.io/cocoapods/v/HandyJSON.svg?style=flat)](http://cocoadocs.org/docsets/HandyJSON)
14
[![Cocoapods Platform](https://img.shields.io/cocoapods/p/HandyJSON.svg?style=flat)](http://cocoadocs.org/docsets/HandyJSON)
Sep 27, 2016
Sep 27, 2016
15
[![Codecov branch](https://img.shields.io/codecov/c/github/alibaba/HandyJSON/master.svg?style=flat)](https://codecov.io/gh/alibaba/HandyJSON/branch/master)
Sep 26, 2016
Sep 26, 2016
16
Nov 19, 2016
Nov 19, 2016
17
## [中文文档](./README_cn.md)
Oct 2, 2016
Oct 2, 2016
18
Sep 20, 2017
Sep 20, 2017
19
## 交流群
20
21
群号: 581331250
22
23
![交流群](qq_group.png)
24
Sep 27, 2016
Sep 27, 2016
25
## Sample Code
Sep 20, 2016
Sep 20, 2016
26
Sep 27, 2016
Sep 27, 2016
27
### Deserialization
Sep 20, 2016
Sep 20, 2016
28
Nov 14, 2016
Nov 14, 2016
29
```swift
Jan 8, 2017
Jan 8, 2017
30
class BasicTypes: HandyJSON {
31
var int: Int = 2
32
var doubleOptional: Double?
33
var stringImplicitlyUnwrapped: String!
Nov 1, 2016
Nov 1, 2016
34
Nov 22, 2016
Nov 22, 2016
35
required init() {}
Sep 27, 2016
Sep 27, 2016
36
}
37
Jan 8, 2017
Jan 8, 2017
38
let jsonString = "{\"doubleOptional\":1.1,\"stringImplicitlyUnwrapped\":\"hello\",\"int\":1}"
Jan 21, 2017
Jan 21, 2017
39
if let object = BasicTypes.deserialize(from: jsonString) {
Jan 8, 2017
Jan 8, 2017
40
print(object.int)
41
print(object.doubleOptional!)
42
print(object.stringImplicitlyUnwrapped)
Sep 27, 2016
Sep 27, 2016
43
}
44
```
45
46
### Serialization
47
Nov 14, 2016
Nov 14, 2016
48
```swift
Sep 27, 2016
Sep 27, 2016
49
Jan 8, 2017
Jan 8, 2017
50
let object = BasicTypes()
51
object.int = 1
52
object.doubleOptional = 1.1
53
object.stringImplicitlyUnwrapped = “hello"
Sep 27, 2016
Sep 27, 2016
54
Jan 8, 2017
Jan 8, 2017
55
print(object.toJSON()!) // serialize to dictionary
56
print(object.toJSONString()!) // serialize to JSON string
57
print(object.toJSONString(prettyPrint: true)!) // serialize to pretty JSON string
Sep 27, 2016
Sep 27, 2016
58
```
59
60
# Content
61
62
- [Features](#features)
63
- [Requirements](#requirements)
64
- [Installation](#installation)
65
- [Cocoapods](#cocoapods)
Oct 5, 2016
Oct 5, 2016
66
- [Carthage](#carthage)
Oct 5, 2016
Oct 5, 2016
67
- [Manually](#manually)
Sep 27, 2016
Sep 27, 2016
68
- [Deserialization](#deserialization)
69
- [The Basics](#the-basics)
Nov 1, 2016
Nov 1, 2016
70
- [Support Struct](#support-struct)
Nov 22, 2016
Nov 22, 2016
71
- [Support Enum Property](#support-enum-property)
Sep 20, 2017
Sep 20, 2017
72
- [Optional/ImplicitlyUnwrappedOptional/Collections/...](#optionalimplicitlyunwrappedoptionalcollections)
Sep 27, 2016
Sep 27, 2016
73
- [Designated Path](#designated-path)
74
- [Composition Object](#composition-object)
75
- [Inheritance Object](#inheritance-object)
Jan 8, 2017
Jan 8, 2017
76
- [JSON Array](#json-array)
Sep 11, 2017
Sep 11, 2017
77
- [Mapping From Dictionary](#mapping-from-dictionary)
Sep 27, 2016
Sep 27, 2016
78
- [Custom Mapping](#custom-mapping)
Sep 20, 2017
Sep 20, 2017
79
- [Date/Data/URL/Decimal/Color](#datedataurldecimalcolor)
Dec 10, 2016
Dec 10, 2016
80
- [Exclude Property](#exclude-property)
Sep 11, 2017
Sep 11, 2017
81
- [Update Existing Model](#update-existing-model)
Sep 27, 2016
Sep 27, 2016
82
- [Supported Property Type](#supported-property-type)
83
- [Serialization](#serialization)
84
- [The Basics](#the-basics)
Jan 8, 2017
Jan 8, 2017
85
- [Mapping And Excluding](#mapping-and-excluding)
Sep 11, 2017
Sep 11, 2017
86
- [FAQ](#faq)
Sep 27, 2016
Sep 27, 2016
87
- [To Do](#to-do)
88
89
# Features
90
Nov 1, 2016
Nov 1, 2016
91
* Serialize/Deserialize Object/JSON to/From JSON/Object
92
93
* Naturally use object property name for mapping, no need to specify a mapping relationship
Sep 27, 2016
Sep 27, 2016
94
Nov 22, 2016
Nov 22, 2016
95
* Support almost all types in Swift, including enum
Sep 20, 2016
Sep 20, 2016
96
Nov 1, 2016
Nov 1, 2016
97
* Support struct
Sep 20, 2016
Sep 20, 2016
98
Sep 11, 2017
Sep 11, 2017
99
* Custom transformations
Sep 20, 2016
Sep 20, 2016
100
Sep 27, 2016
Sep 27, 2016
101
* Type-Adaption, such as string json field maps to int property, int json field maps to string property