Opening .json file

조회 수: 437 (최근 30일)
Luis Eduardo Cofré Lizama
Luis Eduardo Cofré Lizama 2020년 11월 8일
댓글: Luis Eduardo Cofré Lizama 2021년 1월 21일
Hi there, I am new at working with .json files and I am trying to open the data from an IMU. I using the code below, however, when using the jsondecode function I keep getting the following error "Error using jsoncode JSON syntaz error at line 2, column 1 (character 634) extra text". The line and column and character differ depending on the file, but cannot find what ios the "extra text". Any ideas how to solve the problem?
many thanks
eduardo
fileName = '20201108T225105Z_180230000291_gyro_stream.json'; % filename in JSON extension
fid = fopen(fileName); % Opening the file
raw = fread(fid,inf); % Reading the contents
str = char(raw'); % Transformation
fclose(fid); % Closing the file
data = jsondecode(str); % Using the jsondecode function to parse JSON from string

채택된 답변

Manas Meena
Manas Meena 2020년 11월 11일
The most common cause for the extra text error is additional “” signs in the json string. Please check the formatting of the jsoncode. You can also try using the fileread function instead of fread and since you are not providing the full path please add a check before fid to make sure that it is valid.
fileName = 'filename.json'; % filename in JSON extension
str = fileread(fileName); % dedicated for reading files as text
data = jsondecode(str); % Using the jsondecode function to parse JSON from string
The following link provides the information for decoding or creating JSON formatted text.
  댓글 수: 1
Luis Eduardo Cofré Lizama
Luis Eduardo Cofré Lizama 2021년 1월 21일
Thansk Manas, unfortunately couldnt test your suggestion as the files provided by the device I was using are actuallly corrupted and that is problem. The company, I think, is solving the issue.
Cheers

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by