In javascript, you can add a toJSON method to an object and that is what
JSON.stringify will call when converting that object into a string:
var obj = {};
obj.toJSON = function() { return "hello, world"; };
JSON.stringify(obj);// '"hello, world"'
So, if you just add a toJSON to your MyObject, when you stringify that
array, it’ll work automagically.
Gary Katsevman
gkatsev.com
On Sat, Nov 30, 2013 at 11:49 PM, Reza Razavipour <[email protected]
> wrote:
> I have a custom function (constructor). it has a number of member
> variables. I am using Express.
> What I need to do is to return a JSON, to the client, containing an array
> of my custom function.
>
> So lets say I have MyObject, it has member name and password.
> I have an array of MyObject instances. I need to send a JSON representing
> this array.
>
> Do I have to have a jsonify function for MyObject and call this for each
> object in my array?
> Or is there an easier, built-in function for this kind of work?
>
> Reza
>
>
>
>
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" 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/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" 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/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.