goog.json.parse vs JSON.parse

280 views
Skip to first unread message

John Munro

unread,
May 13, 2013, 10:25:26 AM5/13/13
to closure-lib...@googlegroups.com
I'm using goog.net.XhrIo.getResponseJson() but it doesn't have a parameter for a reviver to convert dates (neither does goog.json.parse).  Is there any reason not to use JSON.parse on goog.net.XhrIo.getResponseText()?

Nathan Naze

unread,
May 13, 2013, 10:52:47 AM5/13/13
to closure-library
The code predates the common existence of JSON.parse, thus this is why
it uses goog.json.parse.

Really, it should just be deprecated.

Nathan
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Closure Library Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to closure-library-d...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

John Munro

unread,
May 14, 2013, 4:22:34 PM5/14/13
to closure-lib...@googlegroups.com
When I try to compile the project using Closure I get the error

JSC_TYPE_MISMATCH. assignment to property responseJSON of filevision.net.API.Response
found   : *
required: (Object|null) at ../filevision/net/API.js line 290 : 12

The line in question is

            /**
             * Response as JSON object
             * @type {Object}
             */
            this.responseJSON = window.JSON.parse(xhr.getResponseText(), opt_reviver);

Is there something I can do to the return value of JSON.parse to make the compiler recognize it as an Object or do I need to change the type of the property to {*}?

On Monday, May 13, 2013 10:52:47 AM UTC-4, Nathan Naze wrote:
The code predates the common existence of JSON.parse, thus this is why
it uses goog.json.parse.

Really, it should just be deprecated.

Nathan

On Mon, May 13, 2013 at 10:25 AM, John Munro <ghos...@gmail.com> wrote:
> I'm using goog.net.XhrIo.getResponseJson() but it doesn't have a parameter
> for a reviver to convert dates (neither does goog.json.parse).  Is there any
> reason not to use JSON.parse on goog.net.XhrIo.getResponseText()?
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Closure Library Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to closure-library-discuss+unsub...@googlegroups.com.

Nathan Naze

unread,
May 14, 2013, 4:30:43 PM5/14/13
to closure-library
Do a cast.

https://code.google.com/p/closure-compiler/wiki/AnnotatingTypes

you can also use goog.asserts.asserts here
>> > email to closure-library-d...@googlegroups.com.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Closure Library Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to closure-library-d...@googlegroups.com.

John Munro

unread,
May 14, 2013, 4:48:26 PM5/14/13
to closure-lib...@googlegroups.com
Thanks, I didn't know that was possible - Javascript + Closure is a big elephant to eat in one sitting :)
>> > email to closure-library-discuss+unsub...@googlegroups.com.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Closure Library Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to closure-library-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages