Breaking changes to jsondecode between 2018a and 2018b?
6 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 JSON Format 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!