Opening .json file

424 ビュー (過去 30 日間)
Luis Eduardo Cofré Lizama
Luis Eduardo Cofré Lizama 2020 年 11 月 8 日
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 Center および File ExchangeJSON Format についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by