Giter VIP home page Giter VIP logo

cdljsonpresponseserializer's Introduction

CDLJSONPResponseSerializer

Build Status

This is a class to parse JSONP responses with AFNetworking. It uses Javascript contexts provided by the JavaScriptCore framework.

Usage

#import "AFNetworking.h"
#import "CDLJSONPResponseSerializer.h"
NSString     *urlString  = @"http://derp.example/";
NSString     *callback   = @"foo";
NSDictionary *parameters = @{@"callback": callback};
NSURLRequest *request    =
  [[AFHTTPRequestSerializer serializer] requestWithMethod:@"GET"
                                                URLString:urlString
                                               parameters:parameters];
AFHTTPRequestOperation *op =
  [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer =
  [CDLJSONPResponseSerializer serializerWithCallback:callback];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,
                                    id responseObject) {
  NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  NSLog(@"Error: %@", error);
}];
[[NSOperationQueue mainQueue] addOperation:op];

Requirements

  • Xcode 5.0

  • Target of iOS 7.0 or OS X 10.9

  • AFNetworking 2.0

  • ARC enabled

  • JavaScriptCore framework

Installation with CocoaPods

Add this line to your Podfile:

pod "CDLJSONPResponseSerializer", "~> 0.9"

Running unit tests

In Xcode

In the Tests/ directory, run pod install to set up the workspace. Then you can open the workspace and run tests in the Tests project.

In a terminal

To run the tests from the command line, install xctool with Homebrew:

$ brew update
$ brew install xctool --HEAD

Then, run rake test.

Security Issues

Because JSONP responses are executed in Javascript contexts, a malicious response could cause very large memory or CPU usage. Your app could quit or lock up. This is also true of plain JSON, but JSONP can do it with only a small amount of data, for example:

while(1); // The response will use 100% CPU and never complete.

Credits

Created by Chris Lundie.

License

See the LICENSE file.

cdljsonpresponseserializer's People

Contributors

clundie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cdljsonpresponseserializer's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.