Breaking changes to jsondecode between 2018a and 2018b?

조회 수: 7 (최근 30일)
Zachary David
Zachary David 2019년 7월 19일
댓글: Walter Roberson 2019년 7월 19일
Problem: The same code and files that worked for jsondecode in 2018a and earlier stopped working in 2018b and beyond.
Exception: JSON text must be a character vector or a scalar non-missing string.
The attached article.txt file was written by
json = jsonencode(structObj);
fID = fopen('./data/article.txt', 'w', 'n', 'UTF-8');
fwrite(fID, json, 'char');
fclose(fID);
I have attempted to read it back in by:
fileName = './data/article.txt';
fID = fopen(fileName, 'r', 'n', 'UTF-8');
readIn = native2unicode(fread(fID), 'UTF-8');
value = jsondecode(readIn);
fclose(fID);
This works in 2018a but throws the exceptions at the jsondecode line in 2018b and later

채택된 답변

Walter Roberson
Walter Roberson 2019년 7월 19일
readIn = native2unicode(fread(fID, [1 inf]), 'UTF-8');
That is, you were trying to send a column vector to jsondecode and it needs to be a row vector.
  댓글 수: 2
Zachary David
Zachary David 2019년 7월 19일
Hi Walter,
Thank you very much! That appears to have fixed it.
Do you know the specific change in 2018b that made jsondecode start treating (n,1) and (1,n) vectors differently? Both row and column work in 2018a
Walter Roberson
Walter Roberson 2019년 7월 19일
Sorry, I do not have any reference. The input is documented in R2018a as "character vector" and in MATLAB documentation that has always meant character row vector, with N x 1 being called a character array.

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

추가 답변 (0개)

카테고리

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