Steven Jiang
Steven Jiang

Reputation: 1004

How to get a json file from a website in iOS?

When open link below with a browser:

https://maps.google.co.kr/?q=seoul&output=json

It will start to download a json file.

How to get this file in iOS??

In android it seems using the inputStreamReader to get the content.

Please give me some advise or sample code about it.

Thanks for your help~~

Upvotes: 1

Views: 151

Answers (2)

Steven Jiang
Steven Jiang

Reputation: 1004

I solved it.

It was a very simple way...

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.co.kr?q=%@&output=json", 
                       [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSString *content = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]
                                                        encoding:NSKoreanEncoding  

                                                     error:&error];

It returns a google search result with a full info(address,content,lat,lon etc).

But I don't know why people don't use this way...

If anyone knows about it please tell me~~ thanks~~

Upvotes: 0

Volodymyr B.
Volodymyr B.

Reputation: 3441

You can download it, for example with my class https://github.com/sakrist/ASyncURLConnection

Upvotes: 1

Related Questions