How can I read in a key:value dictionary formatted string into a cell or structured array format?
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Guillaume
2017-5-28
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!