Database Reference
In-Depth Information
}
NSLog(@"Latitude: %4.2f%@",
latitude, northSouth);
NSDecimalNumber *longitudeNum =
[postalCode valueForKey:@"lng"];
float longitude = [longitudeNum floatValue];
NSString *eastWest = @"E";
if (longitude < 0) {
eastWest = @"W";
longitude = - longitude;
}
NSLog(@"Longitude: %4.2f%@",
longitude, eastWest);
The reason that I made that deliberate mistake is to emphasize a point about JSON
serialization, which is that you have to look closely at the shape of the JSON that gets
returned, and know what to expect at any particular point in the tree. Running the
corrected code generates good data in the log:
BuggyWhipChat[9811:b603] Postal Code: 03038
BuggyWhipChat[9811:b603] City: Derry
BuggyWhipChat[9811:b603] County: Rockingham
BuggyWhipChat[9811:b603] State: New Hampshire
BuggyWhipChat[9811:b603] Latitude: 42.89N
BuggyWhipChat[9811:b603] Longitude: 71.30W
Having to generate JSON is somewhat less frequent a task, but it's equally simple to
do. Simply use NSDictionary , NSArray , NSString , NSDecimalNumber and so on to construct
the payload that you wish to send, then use the corollary method dataWithJSONObject
of the NSJSONSerialization class, which will return the JSON NSData that corresponds
to the structure.
SOAP on a Rope
So far, we've been dealing with modern, fairly light-weight web service protocols. Alas,
in many enterprise companies, SOAP is still the name of the game. SOAP has a big
advantage in that you can take a WSDL file and (theoretically) generate client bindings
in a variety of languages and operating systems, and they will all be able to successfully
communicate with the server.
The reality is somewhat less rosy. Things are certainly better than they were a few years
ago, when getting a Java client to talk to an ASP.NET SOAP server could drive you
insane. These days, the impedance mismatches of data types and incomplete data
bindings are largely a thing of the past. What hasn't changed is the God-awful bindings
that you can end up with, especially if you annotate classes and let the framework
generate the WSDL, as is the habit in many projects. And who can blame them, since
WSDLs are one of the most unpleasant file specifications to author?
The reality of life, however, is that there's a good chance you may need to consume a
SOAP server as part of an iOS application. Luckily, there's good tooling available to
 
Search WWH ::




Custom Search