save json file to directory from workspace
23 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I've read a json file into a structure, edited the structure, re-encoded the structure as another json file in the workspace, then attempted to save it in the directory using the save function. It appears to have an issue here as instead of saving correctly it seems to be encoding wrong as shown below. first image is the view when i open the original json file which is correctly displayed. second image is the view when i open the new json file from the directory. it is stored correctly in the workspace so the issue is amost certainly from the save function - what is the correct method for saving the json file?
Thanks,


0 commentaires
Réponse acceptée
Jan
le 24 Mar 2018
Modifié(e) : Jan
le 24 Mar 2018
No, this is not a "wrong" encoding, but save stores the data in MAT file format. sav is simply the wrong function to store a JSON file.
What did you use to import the JSON file?
I'd start with searching in the net. I'd prefer a stable Java implementation like http://vision.is.tohoku.ac.jp/~kyamagu/software/json/. You find many other implementations in the FileExchange: https://www.mathworks.com/matlabcentral/fileexchange/?utf8=%E2%9C%93&term=json . JSONlab is frequently downloaded, but I'm not a fan of it because of the usage of global variables for the communication with the subfunctions. What a pity that such a huge and useful tool suffers from a design flaw.
4 commentaires
Doaa Alamoudi
le 27 Avr 2021
To import json file to matlab
DF = 'filename.json';
fid = fopen(DF);
raw = fread(fid,inf);
str = char(raw');
data = jsondecode(str);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur JSON Format dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!