Your SlideShare is downloading. ×
0
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
JSONModel Lightning Talk
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

JSONModel Lightning Talk

4,215

Published on

The slides from my Lightning Talk for the UIKonf in Berlin. (20 slides / 5min total time)

The slides from my Lightning Talk for the UIKonf in Berlin. (20 slides / 5min total time)

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,215
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
0
Comments
0
Likes
6
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Blah blahBlah blahBlah blahBlah blah !!!!#$!App Store 2008:-connected apps, showing realtime data! Whoa Nelly!- in your pocket! Boom!
  • 2. Communication OK?XML? CSV? binary?<myverylongtagname>1</myverylongtagname>MyName, 1, 2, 5, left, TRUEOther, 5, 4, 3, left, FALSE010000100110010100100000011100110111010101110010011001010010000001110100011011110JSON
  • 3. JSON is awesome1) it’s very SIMPLE!2) supported by tons of languages3) structural data
  • 4. • Step1: Stackoverflow• Step2: click the link in approved answer• Step3:•How to JSON?
  • 5. Simplest approach[[[[[json objectForKey:@”name”] objectAtIndex:1]objectAtIndex: 2] objectForKey:@”value”] boolValue]2009 code2013 code[json[@”name”][1][2][@”value”] boolValue]
  • 6. never!- json ... is nil ...- EXC_BAD_ACCESS- ... unrecognized selector ... [NSString boolValue]- ... index out of bounds ...
  • 7. Pros & Cons• very quick code turnaround!!!• no structure validation• no data validation• difficult to error handle• it’s the road to maintenanceHELL!evolution indicator
  • 8. A better way!NSDictionary* json = [NSJSONSerialization ... ];if (json == nil) [self errorHandleEmptyJSON];if (json[@”name”] == nil)[self errorHandleEmptyName];NSArray* name = json[@”name”];if (name.count<1][self errorHandleWrongJSONStructure];NSNumber* value = name[1][2][@”value”];
  • 9. Forget much? oh noes...Looks good so far, what’s left?- validate the data for all values you use- check if the incoming objects are of theexpected class type (yuicks!)- make sure you decend into the JSONaccording to the incoming structure
  • 10. Pros & cons?• Horribly slow to write code• Difficult to maintain• How do you recover from errorsin the middle of the parsing process???• Better data validation• Better structure validationevolution indicator
  • 11. Data models?The “M” in MVC standsfor “MODEL”Wrap up all the code inclasses for all your models
  • 12. feels good!Your models feature custom initwhich reads the JSON and buildsup the model representationAll IF statements and all the errorhandling is handled within themodel classOther magic you coded at 4.17am on a Thursday
  • 13. Pros & cons• Using a class instead of NSDictionary• OOP 4 Ever!• Very flexible code• Lot of redundant parsing code• Lot of implementation• Still harder to adapt to changesevolution indicator
  • 14. Then what?Throughout 2012 I workedmainly on JSON poweredapplications.In December I was alreadyfed-up with:self.name = json[@”name”];Eureka!
  • 15. JSONModel- import JSON- structure validation- data type validation- data type conversion- atomic operations- error handlingAutomatically does/has:
  • 16. Import JSON.h .mFor relatively simple models eliminatesthe need to code in your .m file
  • 17. Validation@property (strong, nonatomic) NSString* name;What you want is:What you should begetting might be:{“name”:“Name”}It is about what you want to have!
  • 18. Conversion@property (strong, nonatomic) NSURL* blogSiteUrl;What you want is:What you get is:{“blogSiteUrl”:“http://www.yahoo.com”}It is about what you want to have!
  • 19. JSONModelevolution indicatorTakes the hum-drum out ofcodingIt’s very fastGrowing (testing) fan base
  • 20. Thankswww.JSONModel.comImage credits:http://www.clker.comhttp://clipart.christiansunite.comhttp://office.microsoft.com

×