Follow LostMuser on Twitter

Monday, December 20, 2010

iOS HTTP JsonLoader

Here's a nice Json HTTP request loader that I built.

Download it now: JsonLoader.zip

It requires TouchJson, which you can get here: https://github.com/TouchCode/TouchJSON

Here's some example code:


#import "JsonLoader/JsonLoader.h"

@interface myClass {

}

@property (nonatomic, retain) JsonLoader *jsonLoader;

@end

...

@implementation myClass

- (id)init {

if(self = [super init]) {

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.crunchbase.com/v/1/company/google.js"]];

self.jsonLoader = [[[JsonLoader alloc] initWithRequest:request delegate:self] autorelease];
}

returns self;
}

- (void)jsonLoadedSuccessfully:(JsonLoader*)loader json:(id*)json {

NSLog(@"loaded json:%@", json};
}

- (void)dealloc {

self.jsonLoader = nil;

[super dealloc];
}

Edit: Updated it to handle Arrays and other Json types beyond just dictionaries

Sunday, December 19, 2010

Marketing is Evil

Many flowers species use bees to handle cross pollination. They have a synergic relationship where the flower feeds the bee in return for it spreading the flowers pollen to other flowers.

To help the bee find the flower's pollen, it builds these rather large eye-catching petals that reflect light frequencies that will catch the bee's eye.

These petals serve little known purpose beyond attracting the bee's attention. It would appear that these resource could be better invested in deeper roots, longer stems and extra leaves. Interestingly, it is important enough to the flower to market to the bees that it willingly invests its resources in petals.

Taking this understanding and looking over nature you begin to see how deep rooted marketing is. Birds will get prettier to attract a better mate, Bombyliidae (bee flies) look like bees to repel predators, Whales scream across the ocean looking for company.

If you are to condemn marketing, realize you are infact condemning a very core property of the world around you.

Saturday, December 11, 2010

Parsing Flickr's Invalid Json

Flickr's api returns invalid Json. The two main iOS Json parsers barf on any json from Flickr.


Turns out Flickr escapes single quotes (') and apparently this isn't allowed. The Json parser error message is not helpful for figuring this out.


By train and error I figured out doing a simple search to remove the backslashes before single quotes gets around the issue.


Here is the code I used to do so.


str = [str stringByReplacingOccurrencesOfString:@"\\'" withString:@"'"];


Oh yeah one more thing, here's the easy flickr url for getting images:

http://api.flickr.com/services/feeds/photos_public.gne?tags=san+francisco,bicycle,biking,golden+gate+bridge&tagmode=all&format=json

Thursday, December 2, 2010

GetAround

I'm super stoked to be in the pre-release for GetAround. It's essentially a Zip Car service where anyone rent out their car and you can rent other peoples' cars.

Check it out:


Musing's Blog Viewer Webcam



(People reading the blog right now!)