webread not working for JSON

9 ビュー (過去 30 日間)
Leah
Leah 2014 年 12 月 28 日
コメント済み: Leah 2014 年 12 月 30 日
I can read from url's and api's just fine as long as the return format is not JSON. Some examples from matlab help that don't work for me
>> api = 'http://climatedataapi.worldbank.org/climateweb/rest/v1/';
url = [api 'country/cru/tas/year/USA'];
S = webread(url)
S =
Empty matrix: 0-by-1
But this works just fine:
fullURL = ['http://www.mathworks.com/matlabcentral/fileexchange' ...
'?term=urlread'];
str = urlread(fullURL);
>> whos str
Name Size Bytes Class Attributes
str 1x82552 165104 char
Has anyone else had this issue? It use to work just fine for me a few months ago. I wonder if it is some internet setting issue.
  2 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 12 月 29 日
Leah - looking at the example at webread, have you tried to include the options parameter? What happens when you try
options = weboptions('ContentType','text');
data = webread(url,options);
where url is what you have described in your question?
And, what happens if you navigate (in any web browser) to the URL http://climatedataapi.worldbank.org/climateweb/rest/v1/country/cru/tas/year/USA? Do you see the alternating year data from 1901 to 2011?
Leah
Leah 2014 年 12 月 30 日
Thanks for your response Geoff. This magically started working and I haven't been able to reproduce the problem.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeJSON Format についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by