Thanks for your help guys. Got the json thingy working.
Dan, mochijson works out of the box. I used mochijson2.erl. I have
tried it out with 3 implementations of JSON and all three seem to
work. I have tried only encoding so far ,I dare say other functions
will work. Anyways, here's the code for the dummy controller that I
wrote and thank you once again for the link :)
RENDERING JSON FOR A ERLYWEB CONTROLLER
----------------------------------------------------------------------------------
Code below illustrates how to render JSON and raw HTML/TEXT from a
controller.
----------------------------------------------------------------------------------
-module(mock_controller).
-export([index/1, mochi_test/1, lshift_test/1, yaws_test/1]).
index(_) ->
{ response, [ { html, <<"<b>hello json</
b>">> } ] }.
mochi_test(_) ->
{ response, [ { html, mochijson2:encode({struct, [{'mochi',
'json2'}]}) } ] }. %% mochiweb JSON implementation
lshift_test(_) ->
{ response, [ { html, rfc4627:encode({obj, [{'lshift',
'rfc4627'}]}) } ] }. %% rfc4627/Lshift JSON implementation
yaws_test(_) ->
{ response, [ { html, json:encode({struct, [{"yaws",
"json"}]}) } ] }. %% YAWS json implementation
-----------------------------------------------------------------------------------------------------------------------------------
Regards,
Abhijith
On Jun 8, 12:20 am, Abhijith <[EMAIL PROTECTED]> wrote:
> Will post the code on the mailing list once I get it working. Thanks
> for the help :)
>
> On Jun 7, 10:10 pm, "Yariv Sadan" <[EMAIL PROTECTED]> wrote:
>
> > There's also a json module in Yaws (but feel free to use whichever you
> > like better). The way I would use it is as follows:
>
> > {response, [{html, json:encode({array, ["foo", "bar", {struct,
> > [{"key", "val"}]}]})}]}
>
> > Yariv
>
> > On Sat, Jun 7, 2008 at 7:13 AM, Dan Bravender <[EMAIL PROTECTED]> wrote:
>
> > > I know that there is a json module in mochiweb:
> > >http://code.google.com/p/mochiweb/source/browse/trunk/src/mochijson.erl.
> > > Let me know if you get it working in erlyweb :-).
>
> > > Cheers,
> > > Dan
>
> > > On Jun 3, 3:20 am, Abhijith <[EMAIL PROTECTED]> wrote:
> > >> Hi all,
> > >> I want to serve/render json from erlyweb controllers. Czn somebody
> > >> please help me out with this or point me to some resource.
>
> > >> --
> > >> Regards
> > >> Abhijith
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"erlyweb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---