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