Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-27-2011, 05:54 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 104
Shades of Chaos is on a distinguished road
Default JSON with not working url

Hey all,

I am trying to write the contents of a .json file from the interent to a string. The contents all text. I am using
Code:
json = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL];
But if the .json file currently isn't available then the app crashes with writing nothing in the console. Does anyone know how to determine before hand if the file is available or how to make it not crash.

Thanks
Shades of Chaos is offline   Reply With Quote
Old 06-28-2011, 03:25 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

first thing, you can try to use
Code:
NSError *err;

json = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&err];

if(err)
   NSLog(@"Error: %@", err);

if(json)
{
    //do things that involve json
}
however i recommend you to use NSURLConnection or ASIHTTPRequest to retrieve a string, you can find an example in section 4 here: WebService [How-To]
__________________
dany_dev is offline   Reply With Quote
Old 06-28-2011, 11:38 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 104
Shades of Chaos is on a distinguished road
Default

Hey dany thanks for the response. I tried putting in the error code and it still didn't write anything to the console. But I used you webservice post and solved my problem.

Thank you
Shades of Chaos is offline   Reply With Quote
Reply

Bookmarks

Tags
contents, internet, json, string, url

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 324
7 members and 317 guests
chemistry, iOS.Lover, lendo, leostc, Leslie80, pbart, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:29 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0