JSON decode extra character error

조회 수: 10 (최근 30일)
Paulo
Paulo 2024년 12월 2일
답변: Kautuk Raj 2024년 12월 10일
I have tried using both of these scripts to decode json files into matlab structures.
filename='sample.json';
str=fileread(filename);
JSONstruc=jsondecode(str);
filename='sample.json';
fid=fopen(filename);
raw=fread(fid,inf);
str=char(raw');
fclose(fid);
JSONstruc=jsondecode(str);
Both versions work fine for one sample json file but I get the same error for a second json file
Error using jsondecode
JSON syntax error at line 2,column 1(character ____):extra text
I'm using Matlab R2023b.
  댓글 수: 1
Sandeep Mishra
Sandeep Mishra 2024년 12월 2일
Is the error occurring in just one specific file? If so, there might be an issue with that JSON file. Could you please share it for better analysis?

댓글을 달려면 로그인하십시오.

답변 (1개)

Kautuk Raj
Kautuk Raj 2024년 12월 10일
Hi @Paulo,
It looks like jsondecode is throwing an error because the input string is not valid JSON. It may be possible that two JSON files are concatenated together which is causing this issue.
You can inspect your JSON file to check for its validity and carry out the workflow again.

카테고리

Help CenterFile Exchange에서 JSON Format에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by