javascript - js_of_ocaml and Deriving_Json -
i need js_of_ocaml working. there's not information on net, , manual sparse (no snippets or usage examples, no comment sections).
i have card
module on server card
record. i'm sending card list
client using ajax, , there want read , traverse list. end this:
let json = json.unsafe_input (js.string http_frame.xmlhttprequest.content) in
...where json
has type 'a
, according documentation (not when run it, of course).
i can log json##length
, correct length of list. go here? ideally, i'd use deriving_json
type-safe card list
again, use for-loop (not elegant, whatever).
type declarations type name = ... deriving(json)
creates json_name
module. here example.
type card = {a: int; b: string; } deriving(json) type t = card list deriving(json) let _ = let str = json.to_string<t> [{a = 10; b = "abc";}; {a = 20; b = "xyz";}] in let rs = json.from_string<t> str in firebug.console##log(js.string str); list.iter (fun r -> firebug.console##log_2(r.a, js.string r.b)) rs
and i'm not sure why, got "uncaught referenceerror: unix_inet_addr_of_string not defined".
so add function unix_inet_addr_of_string () {return 0;}
js file.
Comments
Post a Comment