When I import google sheet into Matlab, I get the first line imported as the url for my google account sign in

6 次查看(过去 30 天)
I am importing a goolge sheet into Matlab using jasn format. But when I use jasndecode, I get the url to login to google account.
I am accessing a file from my windows directory. It is also on my google drive (maybe that's the issue that is different from answers online, I tried but failed to import google sheet from my google drive).
My code:
fid = fopen('C:/Users/Owner/Documents/Research/MonetaryPolicy/Code/onrates2.json');
raw = fread(fid,inf);
%{ I get result raw(1:4) ans =
60
33
100
11
%}
str = char(raw');
%{ I get this from printing out str: <!doctype html><html lang="en-US" dir="ltr"><head><base href="https://accounts.google.com/v3/signin/"><meta name="referrer" content="origin"><link rel="canonical" href="https://accounts.google.com/v3/
%}
fclose(fid);
rdata = jsondecode(str);
%Error using jsondecode
%JSON syntax error at line 1, column 1 (character 1): expected value but found '<'.

回答(1 个)

Jan
Jan 2022-9-15
编辑:Jan 2022-9-15
If the file starts with
<!doctype html><html lang="en-US" dir="ltr"><head>
it is an HTML file, not a JSON file. Then jsondecode cannot work.
  5 个评论
Jan
Jan 2022-9-29
编辑:Jan 2022-9-29
@Nancy Hammond: This is a misinterpretation. I do not have emotions during writing, but I'm focussed on the actual problem. I wanted to help you to get a solution. Therefore I've mentioned, that you have asked a misleading question. As long as you search at the wrong location, you do not have a chance to find the solution. This will confuse the readers also and I think this is the cause for the lack of other answers.
What a pity, that you interprete my tries to help you as rude and that you assume sarcasm. Maybe I do not find the perfect formulation sometimes, because I'm not a native speaker.
I've spent some time to understand your problem and found the mistake in the description. Don't you see, that this is a polite try to assist you? Obviously my help is not welcome. So, well, good luck!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Google 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by