I want to translate to web by YAWS info from mnesia database. Now i have code:
-define(RECORD_TYPE, albums).
-define(RECORD_KEY_FIELD, album_id).
-record(?RECORD_TYPE,
{?RECORD_KEY_FIELD, artist_id, album, albumpath, image}).
convert_to_json(Lines) ->
Data = [{obj,
[{id, Line#?RECORD_TYPE.album_id},
{aid, Line#?RECORD_TYPE.artist_id},
{path, Line#?RECORD_TYPE.albumpath},
{image, Line#?RECORD_TYPE.image},
{album, Line#?RECORD_TYPE.album}]}
|| Line <- Lines],
JsonData = {obj, [{data, Data}]},
rfc4627:encode(JsonData).
handle('GET', _Arg) ->
io:format("~n ~p:~p GET Request ~n", [?MODULE, ?LINE]),
Records = do(qlc:q([X || X <- mnesia:table(?RECORD_TYPE)])),
Json = convert_to_json(Records),
io:format("~n ~p:~p GET Request Response ~p ~n", [?MODULE, ?LINE, Json]),
{html, Json}.
do(Q)->
F = fun() ->
qlc:e(Q)
end,
{atomic, Value} = mnesia:transaction(F),
Value.
and test.yaws file:
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<erl>
out(Arg) ->
Method = method(Arg) ,
io:format("~p:~p ~p Request ~n", [?MODULE, ?LINE, Method]),
my_json:handle(Method, Arg).
method(Arg) ->
Rec = Arg#arg.req,
Rec#http_request.method.
</erl>
</body>
</html>
But i get binary info in YAWS output:
{"data":[{"id":8,"aid":3,"path":[[47,114,111,111,116,47,101,114,108,97,110,103,47,116,101,115,116,108,105,115,116,47,65,114,116,105,115,116,32,78,117,109,98,101,114,51,47,65,108,98,117,109,32,78,117,109,98,101,114,32,50]],"image":[[102,114,111,110,116,46,106,112,103]],"album":[65,108,98,117,109,32,78,117,109,98,101,114,32,50]},{"id":2,"aid":1,"path":[[47,114,111,111,116,47,101,114,108,97,110,103,47,116,101,115,116,108,105,115,116,47,65,114,116,105,115,116,32,78,117,109,98,101,114,49,47,65,108,98,117,109,32,78,117,109,98,101,114,32,50]],"image":[[99,111,118,101,114,46,112,110,103]],"album":[65,108,98,117,109,32,78,117,109,98,101,114,32,50]},{"id":14,"aid":5,"path":[[47,114,111,111,116,47,101,114,108,97,110,103,47,116,101,115,116,108,105,115,116,47,65,114,116,105,115,116,32,78,117,109,98,101,114,53,47,65,108,98,117,109,32,78,117,109,98,101,114,32,50]],"image":[],"album":[65,108,98,117,109,32,78,117,109,98,101,114,32,50]},{"id":12,"aid":4,"path": ..............
How i can convert this to strings?
P.S. sorry for my english and thanks for any help.