我的数据库中有以下表格:
Questions int:questionId(PK) varchar:questionTitle int:questionNumber int:sectionId(FK)
我在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
我的问题是,无论如何要映射结构?为iphone PHP通信存在兼容性框架吗?
解决方法
您需要构建一个小的“服务”,在json中对您的项进行编码并通过http返回它们,这里的文档是:
http://php.net/manual/en/ref.json.php
正如上面提到的Katfish,您将需要在项目中结合NSURLConnection / NSURLRequest或ASIHTTP [2]库使用SBJSON [1]库.如果您不熟悉Cocoa / Obj-C中的任何http访问方法,ASIHTTP可能更容易.
这是一个很好的例子:
http://blog.zachwaugh.com/post/309924609/how-to-use-json-in-cocoaobjective-c