《《How to use TouchJSON in your iPhone apps》.pdfVIP

  • 2
  • 0
  • 约 9页
  • 2015-10-02 发布于河南
  • 举报

《《How to use TouchJSON in your iPhone apps》.pdf

《《How to use TouchJSON in your iPhone apps》.pdf

How to use TouchJSON in your iPhone apps given at NSCoderNight DC 2009-04-14 by Luis de la Rosa aka @louielouie Founder, Happy Apps LLC What is TouchJSON? • Created by Jonathan Wight (aka @schwa) • Based on his previous code CocoaJSON • Part of umbrella project TouchCode • Winner of Best Open Source Project at iPhoneDevCamp 2 • I’m a committer on the project How do I include it in my project? • Check out the TouchCode project • Copy the files from ./TouchJSON/Source into your project • iPhone doesn’t offer a good way to include frameworks currently How do I get JSON? • The most common way is to get JSON from a Web Service REST API • In simpler terms, you download some JSON from a website How do I get JSON? (More details, please.) // This will issue a request to a web service API via HTTP GET to the URL specified by urlString. // It will return the JSON string returned from the HTTP GET. - (NSString *)jsonFromURLString:(NSString *)urlString { NSURL *url = [NSURL URLWithString:urlString]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; [request setHTTPMethod:@GET]; NSURLResponse *response = nil; NSError *error = nil; NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:response error:error]; [request release]; [self handleError:error]; NSString *resultString = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding]; return [resultString autorelease]; } How do I transform JSON into Cocoa? • You use TouchJSON’s CJSONDeserializer to deserialize a JSON NSString into an NSDictionary containing keys and values. • Each value can itself be another object, so you can have a dee

文档评论(0)

1亿VIP精品文档

相关文档