jSondecode()和jsonencode()的麻烦

43次观看(最近30天)
Rui Zhang
Rui Zhang 2021年5月3日
评论: Rui Zhang2021年5月3日
我有一个JSON文件。我正在尝试在使用MATLAB功能之前测试它们。所以我加了它
str1 = fileread('json_filename1.json');
mydata1 = jsondecode(str1)
str2 = jsonencode(mydata1)
fid = fopen('json_filename2.json','wt')
fprintf(fid,str2)
FCLOSE(FID)
Then I go to the online JSON file editor: https://jsoneditoronline.org/#left=local.jagoxe 加载两个文件。我能够加载'json_filename1.json',但我无法正确加载'json_filename2.json'。我收到以下错误消息:
Failed to switch to "tree “由于无效的JSON模式:
第1行的解析错误:
...,“ errordescription”:“ createAcpath执行
-----------------------^
期待“字符串”,“数字”,“ null”,“ true”,“ false”,“ {','[',got'dot'defined'
看起来像JSondecode()或JSONENCODE()有问题。
另外,当我使用strCMP(str1,str2)时,我看到了它们之间的很大差异。
3条评论
the cyclist
the cyclist 2021年5月3日
不,对不起。
但是,也许您可​​以将JSON提炼成仍然显示出问题的简化和/或模糊的版本,但是您可以分享吗?(这也可能有助于缩小造成问题的原因。)

登录发表评论。

答案(1)

肖恩·德·沃尔斯基(Sean de Wolski)
fprintf(fid,“%s”,str2)
这样,如果JSON中有格式规格字符,它们不会被解释。

标签

社区寻宝

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

Start Hunting!