Opening .json file
249 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 JSON Format 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!