Coder Social home page Coder Social logo

simonhurst / jsonmodel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jsonmodel/jsonmodel

0.0 1.0 0.0 521 KB

Magical Data Modelling Framework for JSON. Create rapidly powerful, atomic and smart data model classes

Home Page: http://www.jsonmodel.com

License: Other

jsonmodel's Introduction

JSONModel


Magical Data Modelling Framework for JSON

JSONModel is a library, which allows rapid creation of smart data models. You can use it in your iOS or OSX apps.

JSONModel does NOT pre-write your code as many other libs do, instead it uses performance optimized code to introspect your model classes at run-time, thus being way more flexible when you need to do changes.

The core task of JSONModel is to help you reduce your Objective-C code to parse and import JSON values to Objective-C objects.

JSONModel automatically introspects your model classes and the structure of your JSON input and reduces drastically the amount of code.

The core task of JSONModel is to import, convert, store and export data - through the JSON data types bottleneck:

Besides this core task JSONModel does also a whole bunch of other tasks, to help you automate as much as possible working with local or remote JSON data.


Requirements

  • iOS 5.0+ (requires NSJSONSerialization)
  • OSX 10.7+ (requires NSJSONSerialization)
  • ARC only

Adding JSONModel to your project

Source files

  1. Download the JSONModel repository as a zip file or clone it
  2. Copy the JSONModel sub-folder into your Xcode project
  3. Build your project and check that there are no compile time errors (if your project is non-arc for example, you will get a compile time error from the JSONModel library)

Cocoa pod

  1. Be sure to update your pods specs:
pod setup
  1. In your Podfile add the JSONModel pod:
pod 'JSONModel'

That's it!

If you want to read more about CocoaPods, have a look at this great tutorial.


Basic usage

  1. Create a new Objective-C class for your data model and make it inherit the JSONModel class.

  2. Declare properties in your header file with the name of the JSON keys you have coming in.

If you are parsing this JSON:

{"countryCode":"DE", "country":"Germany"}

Create the following properties:

#import "JSONModel.h"

@interface LocationModel : JSONModel

@property (strong, nonatomic) NSString* countryCode;
@property (strong, nonatomic) NSString* country;

@end

There's no need to do anything in the .m file.

  1. In your app class include the JSONModel umbrella header:
#import "JSONModelLib.h"
  1. Initialize your model with data:
NSString* json = (fetch here JSON from Internet) ... 
NSError* err = nil;
LocationModel* location = [[LocationModel alloc] initWithString:json error:&err];
NSLog(@"Country: %@", location.country);

or you can use the built-in async initializer to fetch JSON from the web:

LocationModel* location = [[LocationModel alloc] initFromURLWithString:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising" 
                          completion: ^(JSONModel *model, JSONModelError* e) {
                              NSLog("Country: %@, error: %@", location.country, [e localizedDescription]);
                          }];

Detailed documentation and tutorials

Information and examples: http://www.touch-code-magazine.com/JSONModel/

Official website: http://www.jsonmodel.com

JSONModel features

  • automatic data mapping
  • model cascading (models including models)
  • model collections
  • one-shot or on-demand JSON to model objects conversion
  • key mapping - map JSON keys from deeper levels or with mismatching names easily
  • JSON HTTP client - a thin HTTP client for simple async JSON requests

More tutorials to come on ...

  • json validation

  • data transformations

  • error handling

  • custom data validation

  • automatic underscore_naming to camelCaseNaming mapping

  • synchronious and asynchronious networking

  • JSON API client

  • JSON RPC 1.0 client

  • automatic compare and equality features

  • export models back to NSDictionary or JSON text

  • and more.


License

This code is distributed under the terms and conditions of the MIT license.


Contribution guidelines

  • if you are fixing a bug you discovered, please add also a unit test so I know how exactly to reproduce the bug before merging

Contributors

Author: Marin Todorov

Contributors: Christian Hoffmann, Mark Joslin, Julien Vignali


Change-log

Coming soon - Version 0.9 @ tbd

  • Refactor of all networking code
  • Removing all sync request methods
  • Adding network level caching
  • Bug fixes up to issue #22
  • breaking changes due big cleanup and optimization

Version 0.8.3 @ 2013-01-24

  • Bug fixes, optimisation and clean up. Github issues up to #15

Version 0.8.2 @ 2013-01-01

  • Added distribution as a Cocoa Pod

Version 0.8.1 @ 2012-12-31

  • Fixed Xcode workspace for the demo apps

Version 0.8.0 @ 2012-12-31

  • OSX support, test and demos
  • automatic network indicator for iOS
  • bug fixes, speed improvements
  • added better README

Version 0.7.8 @ 2012-12-25

  • Initial release with semantic versioning

jsonmodel's People

Contributors

icanzilb avatar joslinm avatar nashfive avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.