2
我想使用webclient模块来查询couchDB休息接口(我使用它而不是opa couchdb API,因为我需要获得特定数量的文档)。解析一个webclient.Result内容在OPA
这里是用来做查询代码:
listmydocs(dburi)=
match WebClient.Get.try_get(dburi) with
| { failure = _ } -> print("error\n")
| {success=s} -> match WebClient.Result.get_class(s) with
| {success} -> print("{s.content}")
| _ -> print("Error {s.code}")
end
在s.content给出的结果是以下字符串:
{"total_rows":177,"offset":0,"rows":[
{"id":"87dc6b6d9898eff09b1c8602fb00099b","key":"87dc6b6d9898eff09b1c8602fb00099b","value":{"rev":"1-853bd502e3d80d08340f72386a37f13a"}},
{"id":"87dc6b6d9898eff09b1c8602fb000f17","key":"87dc6b6d9898eff09b1c8602fb000f17","value":{"rev":"1-4cb464c6e1b773b9004ad28505a17543"}}
]}
我想知道什么将是最好的方法解析这个字符串得到例如id列表,或者只有行字段? 我试图使用Json.deserialize(s.content),但不知道从那里去哪里。
谢谢,“魔术”opa反序列化方法绝对是我正在寻找的。 – jeant 2012-01-09 09:55:19