6

I have a .json file with valid data. I want to host it online and use the live url in my app. I tried putting the json file in drop box and tried to verify the json data on http://jsonformatter.curiousconcept.com site but it shows "JSON data URL does not contain JSON data" Is there any other way can I achieve this? Thanks.

warpedspeed
  • 1,098
  • 11
  • 28
Obj-Swift
  • 2,802
  • 3
  • 29
  • 50

7 Answers7

18

You can still use Dropbox if you don't want to pay for a hosting provider or if you just want to test your app before paying for one.

To do this, you need to replace the www.dropbox.com part of the URL with dl.dropboxusercontent.com as is said in this Dropbox article.

I'm mainly leaving this answer for the future, as this can be useful for other people (me included).

Carlos Agarie
  • 3,952
  • 1
  • 26
  • 38
18

This is exactly the problem I wanted to solve with http://www.myjson.com An easy and simple solution to hosting JSON.

Lance
  • 181
  • 1
  • 3
5

Okay, so you want to host a static JSON file on a webserver so an iOS app can open and parse it. There are a couple of steps and a slight learning curve but from what I'm reading this may help you.

Step 1: Verify that your JSON is valid since it appears that there's some confusion. Open the JSON in a text-editor like notepad. Copy it and paste it in the text area at this site:

http://jsonlint.com/

If you get a parse error - find the line and edit. If you can't do this or the JSON is valid - stop and resolve this problem.

Step 2: While you could use dropbox to do this its not a good idea for a real app. Get a web host. Depending on your basic skill level you can use a cloud provider like Amazon, Heroku, etc. Based on this question - I'd recommend a basic ftp site. There are a ton of free/cheap webhosts.

https://www.google.com/search?q=cheap+web+hosting

The only thing you'll want to watch out with a "free plan" for is that they don't inject ads into your pages. (I'm looking at you GoDaddy.)

Step 3: (assuming you have an iOS app setup)

Add AFNetworking to your project and set up a AFJSONOperation.

http://afnetworking.com/

And use the following code:

  NSURL *url = [NSURL URLWithString:@"http://www.foo.com/bar.json"];

  NSURLRequest *request = [NSURLRequest requestWithURL:url];

  AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){

        NSLog(@"JSON: %@", JSON);


    }failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {

        NSLog(@"error: %@ response: %@", error, response);


    }];

[operation start];

Edit: removed link to Dropbox article. Added cheap webhost options.

mega6382
  • 9,211
  • 17
  • 48
  • 69
warpedspeed
  • 1,098
  • 11
  • 28
4

You can save your JSON here https://quarkbackend.com - free json hosting

This tool let you manage your files and the urls will not change after updating the file

2

Other than myjson.com, You can host it in pastebin.com and use the "Raw" link to access it. Once advantage of pastebin.com over myjson.com is that you can set a expiry period after which it will be auto deleted.

vine'th
  • 4,890
  • 2
  • 27
  • 27
1

Drop box is not an ideal solution for this. I would use S3 or something of that nature.

Patrick Tescher
  • 3,387
  • 1
  • 18
  • 31
  • There are a bunch of good resources for this, here is one: http://chadthompson.me/2013/05/06/static-web-hosting-with-amazon-s3/ – Patrick Tescher Aug 29 '13 at 20:41
1

Step 1: Create a GitHub Gist account.

Step 2: Create a new Gist file with your JSON content and get the raw URL

For Instance: "https://gist.githubusercontent.com/YOUR_ACCOUNT_NAME/0df1fa45aa11753de0a85893448b22de/raw/YourData.txt";

Step 3: Retrieve the file contents from your app by invoking the WebService in GET request mode.

Shyju M
  • 9,387
  • 4
  • 43
  • 48