How to retrieve data from server without any parsing?
I am developing an application that heavily based on back-end data that comes from data base server. I am using mySQL server.
Yet I am getting data by XML and JSON parsing. But I want to know that is there any way or framework that makes possible to retrieve data with out any parsing like create a connection and then by a query we would get data in data set (like in .NET) ?
Thanks开发者_JS百科...
I think you talk about native data type which will be accepted by iOS without parsing it to native structures. I'll suggest you to send response from back-end in plist format and on app level you can use it as native data object.
For most of my XML parsing needs on iOS I use my CWXMLTranslator
class, that is available as open source at https://github.com/jayway/CWFoundation. It uses a small DSL for translating XML into Objective-C objects.
Basically turning parsing XML like this:
<foo code="42">
<name>Saturnus</name>
<next_url>http://apple.com</next_url>
</foo>
Into a domain object like this:
@interface Foo { }
@property(nonatomic, assign) NSInteger code;
@property(nonatomic, copy) NSString* name;
@property(nonatomic, retain) NSURL* nextURL;
@end
Into something as simple as this:
NSArray* response = [CWXMLTranslator translateContentsOfURL:fooURL
withTranslationNamed:@"FooRequest"
delegate:nil
error:NULL];
Where the translation would be a file named FooRequest.xmltranslation
with contents looking something like this:
foo +> @root : Foo {
.code >> code : NSNumber;
name >> name;
next_url >> nextURL : NSURL;
}
It's a bit more work that the "automagic" tools in .net, but simple enough to handle the most complex of SOAP or WCF.
There is an extensive CWXMLTranslatorDelegate
protocol for handling allot more complex cases, and strange type conversions as well.
精彩评论