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

8 ビュー (過去 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 件のコメント
Nancy Hammond
Nancy Hammond 2022 年 9 月 27 日
Jan Level 10 MVP. Why so snarky? Your responses are rude
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 Center および File ExchangeGoogle についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by