Acquiring a JSON from a webpage
조회 수: 16 (최근 30일)
이전 댓글 표시
Hi all,
I'd need to find a way to acquire a JSON file from a web portal. I can do it manually just by going to the site and save in JSON (see screenshot). However, I'd like to be able to do it directly from Matlab, but webread just returns the HTML code, not the data I'm looking for. I tried using the options:
options = weboptions('ContentType','json');
But it failed. Any idea is welcome
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/698997/image.jpeg)
Thanks,
Tero
댓글 수: 0
답변 (1개)
Yongjian Feng
2021년 7월 30일
Try this:
headers = {'Content-Type' 'application/json'; 'Accept' 'application/json'};
options = weboptions('HeaderFields',headers);
webread('http://ip.jsontest.com', options)
댓글 수: 2
Yongjian Feng
2021년 8월 3일
I see. It seems like you just got back the html for the login page. In general, there shall be an API key for authentication. Or try to put your username/password into the headers as well.
참고 항목
카테고리
Help Center 및 File Exchange에서 JSON Format에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!