user559142
user559142

Reputation: 12517

iPhone App Dev - mysql-> php -> iphone

I have the following table in my database:

Questions
int:questionId(PK)
varchar:questionTitle
int:questionNumber
int:sectionId(FK)

I have built pretty much the same structured class in objective c

#import <Foundation/Foundation.h>

@interface Question : NSObject {
    NSInteger qId;
    NSString* qTitle;
    NSInteger qNumber;  
}

@property (nonatomic) NSInteger qId;
@property (nonatomic, retain) NSString* qTitle;
@property (nonatomic) NSInteger qNumber;

@end


#import "Question.h"


@implementation Question
@synthesize qId, qTitle, qNumber;

@end

My question is, is there anyway to map the structures? do compatibility frameworks exist for iphone php communication?

e.g. get php to echo an object array and assign elements to question objects

Upvotes: 4

Views: 316

Answers (1)

shawnwall
shawnwall

Reputation: 4607

You'll need to build a small "service" that encodes your items in json and returns them via http, here's the docs for that:

http://php.net/manual/en/ref.json.php

As Katfish above mentioned, you'll want ot use the SBJSON[1] library in your project in combination with the NSURLConnection/NSURLRequest or the ASIHTTP[2] library. ASIHTTP is probably easier if you aren't familiar with either method of http access in Cocoa/Obj-C.

Here's a good example:

http://blog.zachwaugh.com/post/309924609/how-to-use-json-in-cocoaobjective-c

[1] http://code.google.com/p/json-framework/

[2] http://allseeing-i.com/ASIHTTPRequest/

Upvotes: 1

Related Questions