IOS - Hosting a JSON file to parse it using a URL

I have a .json file with valid data. I want to post it on the web and use a live url in my application. I tried putting the json file in the drop box and tried to check the json data at http://jsonformatter.curiousconcept.com , but it shows that the "JSON data url does not contain JSON data" Is there any other way to achieve this? Thanks.

+6
source share
7 answers

Ok, so you want to host a static JSON file on a web server so that the iOS application opens and parses it. There are a few steps and a little learning curve, but from what I'm reading, this may help you.

Step 1: Make sure your JSON is valid, as there seems to be some confusion. Open JSON in a text editor, such as notepad. Copy it and paste it into the text area on this site:

http://jsonlint.com/

If you get a parsing error, find the line and edit. If you cannot do this or JSON is valid, stop and resolve this problem.

Step 2: Although you can use dropbox for this, it is not a good idea for a real application. Get a web host. Depending on your basic skill level, you can use a cloud provider such as Amazon, Heroku, etc. Based on this question, I would recommend a basic ftp site. There is a ton of free / cheap web hosts.

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

The only thing you want to watch for the โ€œfree planโ€ is that they donโ€™t add ads to your pages. (I'm looking at you, GoDaddy.)

Step 3: (assuming you have the iOS application installed)

Add AFNetworking to your project and customize 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: Remove the link to the Dropbox article. Added cheap web hosting options.

+5
source

You can still use Dropbox if you do not want to pay for a hosting provider, or just want to test your application before paying for it.

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

Basically, I leave this answer for the future, as it may be useful for other people (including me).

+18
source

This is exactly the problem I wanted to solve using http://www.myjson.com A simple and easy solution to host JSON.

+17
source

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

This tool allows you to manage your files and the URLs do not change after updating the file

+4
source

A drop box is not an ideal solution for this. I would use S3 or something like that.

+1
source

In addition to myjson.com , you can post it on pastebin.com and use the " Raw " link to access it. When the advantage of pastebin.com over myjson.com is that you can set an expiration period after which it will be automatically deleted.

+1
source

Step 1: Create a GitHub Gist Account.

Step 2: Create a New Gist File with JSON Content and Get the Source URL

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

Step 3: Extract the contents of the file from your application by calling WebService in GET request mode.

+1
source

Source: https://habr.com/ru/post/952783/


All Articles