How can I read in a key:value dictionary formatted string into a cell or structured array format?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mark Skylar-Scott
le 28 Mai 2017
Commenté : Mark Skylar-Scott
le 28 Mai 2017
I would like to read the following pythonic dict string (returned by a system command) into either a struct or cell array. The containers.Map class requires pre-parsed cells of keys and values, but is there a pre-existing code for reading this?
{"xlo": -1.909999966621399, "yhi": 1.0, "xhi": 1.0, "n_triangles": 20676, "n_points": 10300, "flat_area_z": [], "n_edges": 32824, "zhi": 4.0, "ylo": -1.6299999952316284, "zlo": -5.8145337670434996e-18, "n_unmatched_edges": -136}
Thanks in advance!
0 commentaires
Réponse acceptée
Guillaume
le 28 Mai 2017
str = '{"xlo": -1.909999966621399, "yhi": 1.0, "xhi": 1.0, "n_triangles": 20676, "n_points": 10300, "flat_area_z": [], "n_edges": 32824, "zhi": 4.0, "ylo": -1.6299999952316284, "zlo": -5.8145337670434996e-18, "n_unmatched_edges": -136}';
s = jsondecode(str)
m = containers.Map(fieldnames(s), struct2cell(s))
Note: in some earlier versions of matlab (at least R2016a) you can use the undocumented matlab.internal.webservices.fromJSON instead of jsondecode.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Call Python from MATLAB 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!