How can we use YYModel to parse nested models?

Source: Internet
Author: User

How can we use YYModel to parse nested models?

During project development, it is inevitable to perform nested model analysis on the obtained data. It is better to have two layers at a time. However, it is a headache for beginners.

Today, let's talk about how to use YYModel to parse nested models. Take the province, city, and district as an example:

1. nested model analysis:

Assume that the data we first obtained is a dictionary array containing the province model (provinceModel), which contains the province name NSString * province,

The children (cityModel) dictionary array contains the NSString * city and children (districtModel) dictionary arrays. The district model contains the district name.

 

2. Use YYModel to parse the nested model:

1. outermost layer: provinceModel (province model): NSString * province, NSArray <cityModel *> * children (the city model is installed in it). You also need to build a dictionary model. m to implement the Protocol:

+ (NSDictionary *) modelContainerPropertyGenericClass {

Return @ {@ "children": [cityModel class]};

}

Returns the type of the object to be stored in the Model Property container. YYModel automatically processes the object.

 

2. layer 2: cityModel (city model): NSString * city, NSArray <districtModel *> * children, therefore. m to implement the Protocol:

+ (NSDictionary *) modelContainerPropertyGenericClass {

Return @ {@ "children": [districtModel class]};

}

Returns the type of the object to be stored in the Model Property container. YYModel automatically processes the object.

3. Layer 3: districtModel (Zone Model): NSString * district.

 

This layer-by-layer resolution will be very clear and I hope it will help you.

 

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.