GS project code reading notes -- josn Parsing

Source: Internet
Author: User

Get the app path and set it to jsonviewcontroller.

Find the bundle file by path

Find the JSON file of the horizontal and vertical screens in the bundle file: viewstruct_landscape.json viewstruct_portrait.json

Parse JSON file: [self
Constructviewwithjsonpath: jsonpath];

Read all data in the JSON File

Nsstring * JSON = [nsstring
Stringwithcontentsoffile: jsonpath encoding: nsutf8stringencoding
Error: & error];

Parse with sbjsonparser:

Sbjsonparser * jsonparser = [sbjsonparser
New];

Id repr = [jsonparser
Objectwithstring: JSON];

If (! Repr ){

Nslog (@ "-jsonvalue failed. Error trace is: % @", [jsonparser
Errortrace]);

[Jsonparser release];}


All data is in Repr

Repr is a container which may be a dictionary or Array

Determine the Repr type:

If ([item iskindofclass: [nsdictionary
Class])

{

// Resolution

}

Else if ([item
Iskindofclass: [nsarray
Class])

{

// Resolution

}

For parsing:

Class, frame, propertylist, content, and subviews are retrieved.

Class: determines whether to end with the Controller, that is, whether the class is a uiviewcontroller or a uiview. If it is a controller, then ......

Frame

Propertylist: this structure is complex. It may contain N {class, frame, propertylist, content, subviews}

Content

Subviews

In class, why do we need to distinguish between uiview and uiviewcontroller? Because the class needs to be initialized later, the initialization information required for these two classes is different.

When parsing these two classes, you should also distinguish them from uiview or uiviewcontroller, because these two different classes determine the attributes to be parsed below and parse the attributes according to their respective rules.

[   {      "class":"SalmonFlipView",      "frame":"{{0, 0}, {768, 1024}}",      "propertyList":{         "frontView":{            "class":"SalmonFlipViewSubViewWithButton",            "frame":"{{0, 0}, {768,1024}}",            "propertyList":{               "flipViewButton":{                  "class":"SalmonButton",                  "frame":"{{134, 437}, {512, 512}}",                  "propertyList":{                     "backgroundColor":{                        "UIColor":{                           "r":0,                           "g":0,                           "b":255,                           "a":1                        }                     },                     "animations":{                        "animation":[                           {                              "class":"CABasicAnimation",                              "propertyList":{                                 "fromValue":{                                    "float":"0"                                 },                                 "toValue":{                                    "float":"1"                                 },                                 "keyPath":{                                    "string":"opacity"                                 },                                 "duration":{                                    "float":"4"                                 }                              }                           }                        ]                     }                  },                  "subViews":[                  ],                  "content":""               }            },            "subViews":[               {                  "class":"UIImageView",                  "frame":"{{0, 0}, {461, 593}}",                  "propertyList":{                     "backgroundColor":{                        "UIColor":{                           "r":51,                           "g":51,                           "b":0,                           "a":1                        }                     },                     "animations":{                        "animation":[                           {                              "class":"CABasicAnimation",                              "propertyList":{                                 "fromValue":{                                    "rect":"{{100, 100}, {0, 0}}"                                 },                                 "toValue":{                                    "rect":"{{0, 0}, {461, 593}}"                                 },                                 "keyPath":{                                    "string":"frame"                                 },                                 "duration":{                                    "float":"2"                                 }                              }                           }                        ]                     }                  },                  "subViews":[                  ],                  "content":""               }            ]         },         "backgroundView":{            "class":"SalmonFlipMoviePlayerView",            "frame":"{{107, 173}, {541, 572}}",            "propertyList":{               "contentURL":{                  "URL":"http:\/\/manager.mediapad.cn\/26\/page_1220.bundle\/1.mp4"               },               "sandBoxContentURL":{                  "URL":"http:\/\/manager.mediapad\/1\/26\/page_1220.bundle\/1.mp4"               },               "closeButton":{                  "class":"SalmonButton",                  "frame":"{{497, 0}, {44, 44}}",                  "propertyList":[                  ],                  "subViews":[                  ],                  "content":"moviePlayerCloseButton.png"               }            },            "subViews":[            ]         }      },      "subViews":[      ]   }]



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.