我已经在许多项目中使用JSONlab很长时间了,但因为它非常慢,有些地方没有达到我的预期,所以我围绕rapidjson编写了一个倍频程包装器:
https://github.com/Andy1978/octave-rapidjson
自述。md显示了一些示例。例如,从服务器获取JSON回复,然后将其转换为结构:
octave:1> x = load_json (urlread ("http://headers.jsontest.com/"))
x =
scalar structure containing the fields:
X-Cloud-Trace-Context = 61910c1954c45fe021d35aeeb5477c20/2702800337619378204
Host = headers.jsontest.com
Accept = */*
octave:2> x.Host
ans = headers.jsontest.com
另一种方式:
octave:11> a.x = 5; a.y = {1,2,"foobar"}; a.z = rand(2); save_json (a)
ans = {
"x": 5.0,
"y": [
1.0,
2.0,
"foobar"
],
"z": [
[
0.6835708677160701,
0.891779233104656
],
[
0.9378550691771155,
0.664043049215685
]
]
}