2016-08-02 5 views
0

예를 들어 간단한 날씨 앱을 만들려고합니다. 내 것은 Air Quality API를위한 것입니다.C#, ios를 사용하여 API에서 JSON 주소 가져 오기

이 코드가 있지만 JSON과 작동하지 않을 것이라고 생각했습니다. 그런 다음

var webClient = new WebClient(); 
... 
var text = e.Result; // get the downloaded text and store in this variable 
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); 
string localFilename = "downloaded.txt"; // local file to save text in 
string localPath = Path.Combine(documentsPath, localFilename); // local path to save file to 
File.WriteAllText(localPath, text); // writes to local storage 
myTextView.Text = text; // updates the TextView element on the screen with downloaded text data 

JSON에 대한 인코딩 방법 그냥

var url = new Uri("https://api.breezometer.com/baqi/?lat=" + latitude + "&lon=" + longitude +"&key=YOUR KEY HERE"); 
webClient.Encoding = Encoding.UTF8; 
webClient.DownloadStringAsync(url); 

임 단지 확실하지. 사람이 대답하시기 바랍니다 알고 있다면 감사 ...

+0

. 둘 다 더 간단한 api를 가지고 있으며 잘 문서화되어 있습니다. –

답변

0

사용 System.Net에서 WebClient 클래스 :

var json = new WebClient().DownloadString("url"); 

원산지 답변 : 나는 HttpClient를 또는 ModernHttpClient를 사용하는 것이 좋습니다 How to get a json string from url?

+0

나는 그것을 시험해 보았다. 그리고 그 시점에서 앱이 추락했다. –

+0

오류가 표시 될 수 있습니까? – Raskayu

+0

시스템 로그를 게시 할 수는 있지만 [link] (https://drive.google.com/file/d/0B66vfwSXdArkRzVRTWZqTnVSTHc/view?usp=sharing) @Raskayu –

관련 문제