0

Hello!

This is for the iphone

This is what i am trying to achieve:

This website expands URLs like bit.ly/miniscurl the creator got an API that says that all you have to do is go to this website:

http://expandurl.appspot.com/expand?url=YOURURL

so when i put:

http://expandurl.appspot.com/expand?url=bit.ly/miniscurl

it returns a new website with this information:

{
    "status": "OK", 
    "end_url": "http:\/\/miniscurl.dafk.net", 
    "redirects": 1, 
    "urls": ["http:\/\/bit.ly\/miniscurl", "http:\/\/miniscurl.dafk.net"], 
    "start_url": "http:\/\/bit.ly\/miniscurl"
}

And that is great! but how do i get that information into an NSString and then search through it for the different tags. so that at last got this:

NSString *status = OK;
NSString *end_url = http:\/\/miniscurl.dafk.net";
etc...

Also a NSArray containing all the redirects (if there are more than one) would have been great!

Conclusion:

I need:

  • a fast and easy way to get HTML source from a website.
  • a fast and easy way to search through NSString and cut it up in different pieces.

Thank you!

Best regards Kristian

1 Answer 1

1

To get the data from an HTTP-server, you can use [NSData dataWithContentsOfURL:].

To parse the data, in this case it seems to be JSON-data, you can use a simple JSON parser like TouchJSON.

Here is some example code I wrote for one of my apps:

NSURL *url = [NSURL URLWithString:@"http://server.com/data.json"];
NSData *rawJsonData = [NSData dataWithContentsOfURL:url];

CJSONDeserializer *parser = [CJSONDeserializer new];
NSError *error;
NSDictionary *jsonDictionary = [parser deserializeAsDictionary:rawJsonData 
                                                         error:&error];

[parser release];

Hope that helps!

Also, it looks like you are new here. Please mark the answer that helps you most by clicking the "√" on the left, thanks!

Sign up to request clarification or add additional context in comments.

1 Comment

Hello! Thanks for the reply =D i got in working by using this SBJson: NSString *url=@"expandurl.appspot.com/expand?url=bit.ly/miniscurl"; NSString *output=[NSString stringWithContentsOfURL:[NSURL URLWithString:url]]; id theObject= [output JSONValue]; NSLog(@"%@",theObject); this gave this output: { "end_url" = "miniscurl.dafk.net"; redirects = 1; "start_url" = "bit.ly/miniscurl"; status = OK; urls = ( "bit.ly/miniscurl", "miniscurl.dafk.net" ); } how would i continue from here? to separate the NSString :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.