Js_of_ocaml and Deriving_Json

I need help for js_of_ocaml to work. There is not much information about this on the net, and the manual is very rare (without fragments or examples of use, without comments).

I have a Card module on a server with a Card entry. I send the card list client using Ajax, and there I want to read and go through this list. As a result, I get the following:

 let json = Json.unsafe_input (Js.string http_frame.XmlHttpRequest.content) in 

... where json is of type 'a , as per the documentation (not when I run it, of course).

I can write json##length and get the correct list length. Where am I going from here? Ideally, I would like to use Deriving_Json for safe input like card list , but I could also use a for loop (not so elegant, but any).

+6
source share
1 answer

In declarations of type type name = ... deriving(Json) , the Json_name module is Json_name . Here is an 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(ra, Js.string rb)) rs 

And I'm not sure why, I got "Uncaught ReferenceError: unix_inet_addr_of_string not defined".

So add function unix_inet_addr_of_string () {return 0;} file in js.

+3
source

Source: https://habr.com/ru/post/950136/


All Articles