SlideShare a Scribd company logo
Luis Rei
LuisRei.com
me@luisrei.com
@lmrei
Developing
iOS
REST
Applications
• WHOAMI
• GLAZEDSOLUTIONS.COM
• HTML5 Mobile Apps - Friday 15h Main Stage
• It’s awesome: iPhone, iPad, iPod Touch
• Best Mobile App Dev Platform (by light years)
• Objective-C + Foundation + Cocoa
• Lots of potential users
• lots of potentially paying users
Why iOS
• Software architecture for distributed systems
• say web services/APIs
• Client-Server
• Works over HTTP & URI-based
• http://api.twitter.com/1/statuses/public_timeline.json
REST Quick Intro
• There’s always something you need in “the cloud”
• Data or processing power
• More true on mobile
• Universal: mobile, desktop, web clients
• It’s easy to implement server side ( at least the basic stuff)
• and everyone is doing it (twitter, github, amazon, google, ...)
• It’s easy to implement on the client
Why REST
REST/REST-Like APIs
iOS REST Recipe
Function Library I Use Currently iOS Boilerplate
HTTP Requests ASIHTTPRequest AFNetworking
JSON
SBJson
(AKA json-framework)
JSONkit
Image Caching
AFNetworking
(I previously used HJCache)
AFNetworking
Pull-To-Refresh
PullToRefreshTableViewController
by Leah Culver
EGOTableViewPullToRefresh
HUD
SVProgessHUD
(I previously used DSActivityView)
SVProgessHUD
• Am I connected to the internet?
• Wifi or Cellular?
Reachability
(SystemConfiguration framework)
NSString * const SRVR = @"api.example.com";
-(BOOL)reachable
{
    Reachability *r = [Reachability reachabilityWithHostName:SRVR];
    NetworkStatus internetStatus = [r currentReachabilityStatus];
    if(internetStatus == NotReachable) {
        return NO;
    }
    return YES;
}
NotReachable
ReachableViaWifi
ReachableViaWWAN
GET
- (void)makeGetRequest
{
NSURL *url = [NSURL URLWithString:@"http://api.example.com"];
ASIHTTPRequest *request =
[ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error && [request responseStatusCode] == 200)
{
NSString *response = [request responseString];
//NSData *responseData = [request responseData];
}
Errors
else if(error)
NSLog(@"request error: %@",[error localizedDescription]);
else if([request responseStatusCode] != 200)
NSLog(@"server says: %@", [request responseString]);
}
•The app continues to execute
•UI continues to be responsive
•The request runs in the background
•Two (common) ways of doing it in iOS:
•Delegate
•Block
Asynchronous Requests
• The delegator object has a delegate property that
points to the delegate object
• A delegate acts when its delegator encounters a
certain event
• The delegate adopts a protocol
• We’ll need 2 methods: success & failure
Cocoa Delegate Pattern
Asynchronous GET
- (void)makeGetRequest
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
// DELEGATE METHODS:
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSString *responseString = [request responseString];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}
Cocoa Blocks
• Ad hoc function body as an expression
• Carry their code & the data they need
• ideal for callbacks
• We’ll need 2 blocks: success & failure
Building Blocks
- (void)makeGetRequest
{
NSURL *url = [NSURL URLWithString:@"http://api.example.com"];
__block ASIHTTPRequest *request =
[ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
NSString *responseString = [request responseString];
}];
[request setFailedBlock:^{
NSError *error = [request error];
}];
[request startAsynchronous];
}
SVProgressHUD
#import "SVProgressHUD.h"
- (void)makeGetRequest
{
NSURL *url = [NSURL URLWithString:@"http://api.example.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[SVProgressHUD showWithStatus:@"Fetching data"];
[request startSynchronous];
if (![request error])
{
" [SVProgressHUD dismissWithSuccess:@"Fetch Successful"];
...
}
else {
" [SVProgressHUD dismissWithError:@"Fetch Failed"];
...
}
}
Where to Load Data
• viewDidLoad / viewWillAppear
• Make the asynchronous request
• Show HUD or other “loading” indicators
• LOADED = NO;
• Delegate
• LOADED = YES;
• Reload table
• Partial Load + Pagination
• Load more at the end of the table
PullToRefresh
Developing iOS REST Applications
#import "PullRefreshTableViewController.h"
@interface MyTableViewController : PullRefreshTableViewController
- (void)refresh
{
  [self performSelector:@selector(add) withObject:nil afterDelay:2.0];
}
- (void) add
{
...
[self stopLoading];
}
.m
.h
Background Loading
& Caching Images
#import "UIImageView+AFNetworking.h"
NSURL *imageURL = [NSURL URLWithString:@”http://example.com/picture.jpg”];
UIImageView *image = [[UIImageView alloc] init];
[image setImageWithURL:imageURL];
Updating My Profile Picture
•Modify an existing record
•Authenticate
•Upload a file
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setRequestMethod:@"PUT"]; //REST modify using PUT
[request setPostFormat:ASIMultipartFormDataPostFormat];
// authentication
[request setUsername:username];
[request setPassword:password];
[request setFile:jpgPath forKey:@"image"];
"
[request startSynchronous];
POST & DELETE
[request setRequestMethod:@"POST"];
[request setRequestMethod:@"DELETE"];
I JSON (because it’s not XML)
JSON OBJECTIVE-C/FOUNDATION
Object NSDictionary
Array NSArray
String NSString
Number NSNumber
Boolean NSNumber (0 or 1)
1. Download a JSON string (via an http request)
2.Convert it to native data structures (parsing)
3.Use the native data structures
Parsing
[request startSynchronous];
...
SBJsonParser *prsr = [[[SBJsonParser alloc] init] autorelease];
// object
NSDictionary *data = [prsr objectWithString:[request responseString]];
// or Array
NSArray *data = [parsr objectWithString:[request responseString]];
INCEPTION
[{[{}]}]
An array of
objects with an
array of objects
[
	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  "name":	
  "object1",
	
  	
  	
  	
  	
  	
  	
  	
  "sub":	
  [
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "name":	
  "subobject1"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "name":	
  "subobject2"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }
	
  	
  	
  	
  	
  	
  	
  	
  ]
	
  	
  	
  	
  },
	
  	
  	
  
]
or rather JCEPTION
NSArray *jArray = [prsr objectWithString:data];
NSDictionary *obj1 = [jArray objectAtIndex:0];
NSString *obj1Name = [obj1 objectForKey:@”name”];
NSArray *obj1SubArray = [obj1 objectForKey:@”sub”];
NSDictionary *subObj1 = [obj1SubArray objectAtIndex:0];
NSNumber *subObj1Val = [subObj1 objectForKey@”value”];
[
	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  "name":	
  "object1",
	
  	
  	
  	
  	
  	
  	
  	
  "sub":	
  [
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "name":	
  "subobject1"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "value":	
  1
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }
	
  	
  	
  	
  	
  	
  	
  	
  ]
	
  	
  	
  	
  },
]
...[[[prsr objectWithSring:data] objectAtIndex:0] objectForKey:@”sub]...
Developing iOS REST Applications

More Related Content

What's hot (20)

KEY
iOS5 NewStuff
deenna_vargilz
 
PDF
JavaScript Promise
Joseph Chiang
 
PDF
How to write easy-to-test JavaScript
Ynon Perek
 
PPTX
SenchaCon 2016: Ext JS + React: A Match Made in UX Heaven - Mark Brocato
Sencha
 
PDF
HTML5 APIs - Where no man has gone before! - Altran
Robert Nyman
 
PDF
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Ryan Weaver
 
PDF
Webapps without the web
Remy Sharp
 
PDF
REST/JSON/CoreData Example Code - A Tour
Carl Brown
 
PDF
OneRing @ OSCamp 2010
Qiangning Hong
 
PDF
Promise pattern
Sebastiaan Deckers
 
PDF
iPhone Appleless Apps
Remy Sharp
 
PDF
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
Peter Friese
 
PDF
jQuery in 15 minutes
Simon Willison
 
PDF
Django Celery - A distributed task queue
Alex Eftimie
 
PDF
An Introduction to Celery
Idan Gazit
 
KEY
New Design of OneRing
Qiangning Hong
 
PDF
Tips and tricks for building api heavy ruby on rails applications
Tim Cull
 
PPTX
Python Code Camp for Professionals 2/4
DEVCON
 
PDF
Behind the curtain - How Django handles a request
Daniel Hepper
 
PDF
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
Robert Nyman
 
iOS5 NewStuff
deenna_vargilz
 
JavaScript Promise
Joseph Chiang
 
How to write easy-to-test JavaScript
Ynon Perek
 
SenchaCon 2016: Ext JS + React: A Match Made in UX Heaven - Mark Brocato
Sencha
 
HTML5 APIs - Where no man has gone before! - Altran
Robert Nyman
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Ryan Weaver
 
Webapps without the web
Remy Sharp
 
REST/JSON/CoreData Example Code - A Tour
Carl Brown
 
OneRing @ OSCamp 2010
Qiangning Hong
 
Promise pattern
Sebastiaan Deckers
 
iPhone Appleless Apps
Remy Sharp
 
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
Peter Friese
 
jQuery in 15 minutes
Simon Willison
 
Django Celery - A distributed task queue
Alex Eftimie
 
An Introduction to Celery
Idan Gazit
 
New Design of OneRing
Qiangning Hong
 
Tips and tricks for building api heavy ruby on rails applications
Tim Cull
 
Python Code Camp for Professionals 2/4
DEVCON
 
Behind the curtain - How Django handles a request
Daniel Hepper
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
Robert Nyman
 

Similar to Developing iOS REST Applications (20)

PDF
Webエンジニアから見たiOS5
Satoshi Asano
 
PDF
Concurrent networking - made easy
Amazing Applications AB
 
PDF
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Sarp Erdag
 
PPT
iOS Multithreading
Richa Jain
 
PDF
Elements for an iOS Backend
Laurent Cerveau
 
PPT
Connecting to a REST API in iOS
gillygize
 
ZIP
iPhone and Rails integration
Paul Ardeleanu
 
KEY
Effective iOS Network Programming Techniques
Ben Scheirman
 
PPT
Meetup uikit programming
joaopmaia
 
PDF
07 objective-c session 7
Amr Elghadban (AmrAngry)
 
KEY
Objective-C Crash Course for Web Developers
Joris Verbogt
 
KEY
RubyMotion
Mark
 
PPTX
What's Parse
Tsutomu Ogasawara
 
PDF
MFF UK - Advanced iOS Topics
Petr Dvorak
 
PDF
iOS 2 - The practical Stuff
Petr Dvorak
 
PPT
iphone presentation
Dhananjay Fartyal
 
PDF
iPhone: Http Connection
Jussi Pohjolainen
 
PDF
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
Jonathan Engelsma
 
PDF
iOS Swift application architecture
Romain Rochegude
 
KEY
Introduction to Restkit
petertmarks
 
Webエンジニアから見たiOS5
Satoshi Asano
 
Concurrent networking - made easy
Amazing Applications AB
 
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Sarp Erdag
 
iOS Multithreading
Richa Jain
 
Elements for an iOS Backend
Laurent Cerveau
 
Connecting to a REST API in iOS
gillygize
 
iPhone and Rails integration
Paul Ardeleanu
 
Effective iOS Network Programming Techniques
Ben Scheirman
 
Meetup uikit programming
joaopmaia
 
07 objective-c session 7
Amr Elghadban (AmrAngry)
 
Objective-C Crash Course for Web Developers
Joris Verbogt
 
RubyMotion
Mark
 
What's Parse
Tsutomu Ogasawara
 
MFF UK - Advanced iOS Topics
Petr Dvorak
 
iOS 2 - The practical Stuff
Petr Dvorak
 
iphone presentation
Dhananjay Fartyal
 
iPhone: Http Connection
Jussi Pohjolainen
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
Jonathan Engelsma
 
iOS Swift application architecture
Romain Rochegude
 
Introduction to Restkit
petertmarks
 
Ad

Recently uploaded (20)

PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Ad

Developing iOS REST Applications

  • 2. • WHOAMI • GLAZEDSOLUTIONS.COM • HTML5 Mobile Apps - Friday 15h Main Stage
  • 3. • It’s awesome: iPhone, iPad, iPod Touch • Best Mobile App Dev Platform (by light years) • Objective-C + Foundation + Cocoa • Lots of potential users • lots of potentially paying users Why iOS
  • 4. • Software architecture for distributed systems • say web services/APIs • Client-Server • Works over HTTP & URI-based • http://api.twitter.com/1/statuses/public_timeline.json REST Quick Intro
  • 5. • There’s always something you need in “the cloud” • Data or processing power • More true on mobile • Universal: mobile, desktop, web clients • It’s easy to implement server side ( at least the basic stuff) • and everyone is doing it (twitter, github, amazon, google, ...) • It’s easy to implement on the client Why REST
  • 7. iOS REST Recipe Function Library I Use Currently iOS Boilerplate HTTP Requests ASIHTTPRequest AFNetworking JSON SBJson (AKA json-framework) JSONkit Image Caching AFNetworking (I previously used HJCache) AFNetworking Pull-To-Refresh PullToRefreshTableViewController by Leah Culver EGOTableViewPullToRefresh HUD SVProgessHUD (I previously used DSActivityView) SVProgessHUD
  • 8. • Am I connected to the internet? • Wifi or Cellular? Reachability (SystemConfiguration framework)
  • 9. NSString * const SRVR = @"api.example.com"; -(BOOL)reachable {     Reachability *r = [Reachability reachabilityWithHostName:SRVR];     NetworkStatus internetStatus = [r currentReachabilityStatus];     if(internetStatus == NotReachable) {         return NO;     }     return YES; } NotReachable ReachableViaWifi ReachableViaWWAN
  • 10. GET - (void)makeGetRequest { NSURL *url = [NSURL URLWithString:@"http://api.example.com"]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request startSynchronous]; NSError *error = [request error]; if (!error && [request responseStatusCode] == 200) { NSString *response = [request responseString]; //NSData *responseData = [request responseData]; }
  • 11. Errors else if(error) NSLog(@"request error: %@",[error localizedDescription]); else if([request responseStatusCode] != 200) NSLog(@"server says: %@", [request responseString]); }
  • 12. •The app continues to execute •UI continues to be responsive •The request runs in the background •Two (common) ways of doing it in iOS: •Delegate •Block Asynchronous Requests
  • 13. • The delegator object has a delegate property that points to the delegate object • A delegate acts when its delegator encounters a certain event • The delegate adopts a protocol • We’ll need 2 methods: success & failure Cocoa Delegate Pattern
  • 14. Asynchronous GET - (void)makeGetRequest { NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self]; [request startAsynchronous]; } // DELEGATE METHODS: - (void)requestFinished:(ASIHTTPRequest *)request { NSString *responseString = [request responseString]; } - (void)requestFailed:(ASIHTTPRequest *)request { NSError *error = [request error]; }
  • 15. Cocoa Blocks • Ad hoc function body as an expression • Carry their code & the data they need • ideal for callbacks • We’ll need 2 blocks: success & failure
  • 16. Building Blocks - (void)makeGetRequest { NSURL *url = [NSURL URLWithString:@"http://api.example.com"]; __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setCompletionBlock:^{ NSString *responseString = [request responseString]; }]; [request setFailedBlock:^{ NSError *error = [request error]; }]; [request startAsynchronous]; }
  • 18. #import "SVProgressHUD.h" - (void)makeGetRequest { NSURL *url = [NSURL URLWithString:@"http://api.example.com"]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [SVProgressHUD showWithStatus:@"Fetching data"]; [request startSynchronous]; if (![request error]) { " [SVProgressHUD dismissWithSuccess:@"Fetch Successful"]; ... } else { " [SVProgressHUD dismissWithError:@"Fetch Failed"]; ... } }
  • 19. Where to Load Data • viewDidLoad / viewWillAppear • Make the asynchronous request • Show HUD or other “loading” indicators • LOADED = NO; • Delegate • LOADED = YES; • Reload table • Partial Load + Pagination • Load more at the end of the table
  • 22. #import "PullRefreshTableViewController.h" @interface MyTableViewController : PullRefreshTableViewController - (void)refresh {   [self performSelector:@selector(add) withObject:nil afterDelay:2.0]; } - (void) add { ... [self stopLoading]; } .m .h
  • 24. #import "UIImageView+AFNetworking.h" NSURL *imageURL = [NSURL URLWithString:@”http://example.com/picture.jpg”]; UIImageView *image = [[UIImageView alloc] init]; [image setImageWithURL:imageURL];
  • 25. Updating My Profile Picture •Modify an existing record •Authenticate •Upload a file
  • 26. ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; [request setRequestMethod:@"PUT"]; //REST modify using PUT [request setPostFormat:ASIMultipartFormDataPostFormat]; // authentication [request setUsername:username]; [request setPassword:password]; [request setFile:jpgPath forKey:@"image"]; " [request startSynchronous];
  • 27. POST & DELETE [request setRequestMethod:@"POST"]; [request setRequestMethod:@"DELETE"];
  • 28. I JSON (because it’s not XML) JSON OBJECTIVE-C/FOUNDATION Object NSDictionary Array NSArray String NSString Number NSNumber Boolean NSNumber (0 or 1)
  • 29. 1. Download a JSON string (via an http request) 2.Convert it to native data structures (parsing) 3.Use the native data structures
  • 30. Parsing [request startSynchronous]; ... SBJsonParser *prsr = [[[SBJsonParser alloc] init] autorelease]; // object NSDictionary *data = [prsr objectWithString:[request responseString]]; // or Array NSArray *data = [parsr objectWithString:[request responseString]];
  • 31. INCEPTION [{[{}]}] An array of objects with an array of objects [        {                "name":  "object1",                "sub":  [                        {                                "name":  "subobject1"                        },                        {                                "name":  "subobject2"                        }                ]        },       ] or rather JCEPTION
  • 32. NSArray *jArray = [prsr objectWithString:data]; NSDictionary *obj1 = [jArray objectAtIndex:0]; NSString *obj1Name = [obj1 objectForKey:@”name”]; NSArray *obj1SubArray = [obj1 objectForKey:@”sub”]; NSDictionary *subObj1 = [obj1SubArray objectAtIndex:0]; NSNumber *subObj1Val = [subObj1 objectForKey@”value”]; [        {                "name":  "object1",                "sub":  [                        {                                "name":  "subobject1"                        },                        {                                "value":  1                        }                ]        }, ] ...[[[prsr objectWithSring:data] objectAtIndex:0] objectForKey:@”sub]...