Mjextension use of IOS JSON parsing framework

Source: Internet
Author: User

1. plist→ Model Array

Reference #import "MJExtension.h" in the controller

Model array = [model class name objectarraywithfilename:@ "filename. plist"];

2. Optimization of NSLog, solve the problem when debugging, print model, only print out memory address

How to use: in a. m file of a model class, reference #import "MJExtension.h"

Between the @implementation and the @end, write Mjlogallivrs.

3. Optimization of the nscoding, no need to write cumbersome solutions and archiving methods

How to use: in a. m file of a model class, reference #import "MJExtension.h"

Between the @implementation and the @end, write Mjcodingimplementation.

4. Dictionary arrays → model arrays

4.1 Scene One: [ dictionary 1,

Dictionary 2,

Dictionary 3 ]

If each dictionary is a model, you can use the

Nsarray *modelarray = [model class name Objectarraywithkeyvaluesarray: Field array];

4.2 Scene Two: On the basis of scenario one, each dictionary has an array (assuming the array's key value is Arrayname), the array contains several identical models, using the following method

How to use:

First, in the model class. m file, introduce #import "MJExtension.h"

And then write between the @implementation and the @end.

-(Nsdictionary *) Objectclassinarray

{

return @{@ "Arrayname": [Model Class name class]};

}

5.If the server passed the dictionary in the Dictionary array of key, is the keyword in OC, and the premise of using mjextention is that the model of the property name and array of key is consistent.(Case sensitive), what to do?

Using Replacedkeyfrompropertyname

How to use: 1. Introducing "MJExtension.h" to the model class. m file

2. Implementation methods

+ (Nsdictionary *) replacedkeyfrompropertyname

{

Return @{@ "non-keyword attribute name": @ "Array of key"};

}

6. Single dictionary → single model

+ (Instancetype) objectwithkeyvalues: (Nsdictionary *) keyvalues

Mjextension use of IOS JSON parsing framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.