By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,182 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

JSON object not parsing in firefox

P: n/a
Hi
The JSON object I am using is as below . this object is returned after
an AJAX call

{"application" :[
{optionValue:"101", optionDisplay: "estmt"},
{optionValue:"11", optionDisplay: "Arif"},
{optionValue:"12", optionDisplay: "JC"}
]}
In the JS i am using the below code

data = ajaxRequest.responseText ;
var jsonOBJ = eval('(' + data + ')');
len = jsonOBJ.application.length ;
key = jsonOBJ.application[i].optionValue ;
value = jsonOBJ.application[i].optionDisplay ;
Internet Explorer is able to process the above code , but while trying
from Firefox , I am getting the below error message

jsonOBJ has no properties
[Break on this error] len = jsonOBJ.application.length ;

Please help

Thanks
S

Sep 27 '07 #1
Share this Question
Share on Google+
11 Replies


P: n/a
On Sep 27, 1:57 pm, saril...@gmail.com wrote:
Hi
The JSON object I am using is as below . this object is returned after
an AJAX call

{"application" :[
{optionValue:"101", optionDisplay: "estmt"},
{optionValue:"11", optionDisplay: "Arif"},
{optionValue:"12", optionDisplay: "JC"}
]}

In the JS i am using the below code

data = ajaxRequest.responseText ;
var jsonOBJ = eval('(' + data + ')');
len = jsonOBJ.application.length ;
key = jsonOBJ.application[i].optionValue ;
value = jsonOBJ.application[i].optionDisplay ;

Internet Explorer is able to process the above code , but while trying
from Firefox , I am getting the below error message

jsonOBJ has no properties
[Break on this error] len = jsonOBJ.application.length ;

Please help

Thanks
S
I couldn't break Firefox with this:

var data = '{"application" :[\n\r{optionValue:"101", optionDisplay:
"estmt"},\n\r {optionValue:"11", optionDisplay: "Arif"},\n\r
{optionValue:"12", optionDisplay: "JC"}\n\r ]}';
var jsonOBJ = eval('(' + data + ')');
len = jsonOBJ.application.length;
alert(len);

Are you sure about the responseText value?

Sep 27 '07 #2

P: n/a
On Sep 27, 11:11 am, David Mark <dmark.cins...@gmail.comwrote:
On Sep 27, 1:57 pm, saril...@gmail.com wrote:


Hi
The JSON object I am using is as below . this object is returned after
an AJAX call
{"application" :[
{optionValue:"101", optionDisplay: "estmt"},
{optionValue:"11", optionDisplay: "Arif"},
{optionValue:"12", optionDisplay: "JC"}
]}
In the JS i am using the below code
data = ajaxRequest.responseText ;
var jsonOBJ = eval('(' + data + ')');
len = jsonOBJ.application.length ;
key = jsonOBJ.application[i].optionValue ;
value = jsonOBJ.application[i].optionDisplay ;
Internet Explorer is able to process the above code , but while trying
from Firefox , I am getting the below error message
jsonOBJ has no properties
[Break on this error] len = jsonOBJ.application.length ;
Please help
Thanks
S

I couldn't break Firefox with this:

var data = '{"application" :[\n\r{optionValue:"101", optionDisplay:
"estmt"},\n\r {optionValue:"11", optionDisplay: "Arif"},\n\r
{optionValue:"12", optionDisplay: "JC"}\n\r ]}';
var jsonOBJ = eval('(' + data + ')');
len = jsonOBJ.application.length;
alert(len);

Are you sure about the responseText value?- Hide quoted text -

- Show quoted text -
Hi
Thanks for the reply . I am geting the responseText value as below

{"application" :[ {optionValue:"101", optionDisplay: "estmt"},
{optionValue:"11", optionDisplay: "Arif"
},{optionValue:"12", optionDisplay: "JC"}]}
jsonOBJ has no properties
[Break on this error] len = jsonOBJ.application.length ;

appreciate your help

Sep 27 '07 #3

P: n/a
On Sep 27, 2:31 pm, saril...@gmail.com wrote:
On Sep 27, 11:11 am, David Mark <dmark.cins...@gmail.comwrote:


On Sep 27, 1:57 pm, saril...@gmail.com wrote:
Hi
The JSON object I am using is as below . this object is returned after
an AJAX call
{"application" :[
{optionValue:"101", optionDisplay: "estmt"},
{optionValue:"11", optionDisplay: "Arif"},
{optionValue:"12", optionDisplay: "JC"}
]}
In the JS i am using the below code
data = ajaxRequest.responseText ;
var jsonOBJ = eval('(' + data + ')');
len = jsonOBJ.application.length ;
key = jsonOBJ.application[i].optionValue ;
value = jsonOBJ.application[i].optionDisplay ;
Internet Explorer is able to process the above code , but while trying
from Firefox , I am getting the below error message
jsonOBJ has no properties
[Break on this error] len = jsonOBJ.application.length ;
Please help
Thanks
S
I couldn't break Firefox with this:
var data = '{"application" :[\n\r{optionValue:"101", optionDisplay:
"estmt"},\n\r {optionValue:"11", optionDisplay: "Arif"},\n\r
{optionValue:"12", optionDisplay: "JC"}\n\r ]}';
var jsonOBJ = eval('(' + data + ')');
len = jsonOBJ.application.length;
alert(len);
Are you sure about the responseText value?- Hide quoted text -
- Show quoted text -

Hi
Thanks for the reply . I am geting the responseText value as below

{"application" :[ {optionValue:"101", optionDisplay: "estmt"},
{optionValue:"11", optionDisplay: "Arif"

},{optionValue:"12", optionDisplay: "JC"}]}

jsonOBJ has no properties
[Break on this error] len = jsonOBJ.application.length ;

appreciate your help
So try what I did. Does it work for you?

Sep 27 '07 #4

P: n/a
Thomas 'PointedEars' Lahn wrote:
Thomas 'PointedEars' Lahn wrote:
>sa******@gmail.com wrote:
>>[...] I am geting the responseText value as below

{"application" :[ {optionValue:"101", optionDisplay: "estmt"},
{optionValue:"11", optionDisplay: "Arif"
},{optionValue:"12", optionDisplay: "JC"}]}
Evaluating that results in a compile error:

| Error: invalid label

Tested in Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7)
Gecko/20070914 Firefox/2.0.0.7 (with Firebug 1.05).

In contrast,

[ {optionValue:"101", optionDisplay: "estmt"}, {optionValue:"11",
optionDisplay: "Arif"},{optionValue:"12", optionDisplay: "JC"}]

evaluates fine.

{application: [ {optionValue:"102", optionDisplay: "estmt"},
{optionValue:"11", optionDisplay: "Arif"},{optionValue:"12", optionDisplay:
"JC"}]}

is OK, too.
I presume the reason why it breaks with `"application":' is that the outer
`{...}' is regarded as delimiters of a block statement by eval(), and not as
delimiters of the Object literal notation. Hence eval()uating the variant
with `application:' yields only the Array object, which has no `application'
property. Both `"application":' and `application:' are merely regarded as
labels in a block statement there, with the former being invalid.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Sep 27 '07 #5

P: n/a
On Sep 27, 12:26 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Thomas 'PointedEars' Lahn wrote:
Thomas 'PointedEars' Lahn wrote:
saril...@gmail.com wrote:
[...] I am geting the responseText value as below
>{"application" :[ {optionValue:"101", optionDisplay: "estmt"},
{optionValue:"11", optionDisplay: "Arif"
},{optionValue:"12", optionDisplay: "JC"}]}
Evaluating that results in a compile error:
| Error: invalid label
Tested in Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7)
Gecko/20070914 Firefox/2.0.0.7 (with Firebug 1.05).
In contrast,
[ {optionValue:"101", optionDisplay: "estmt"}, {optionValue:"11",
optionDisplay: "Arif"},{optionValue:"12", optionDisplay: "JC"}]
evaluates fine.
{application: [ {optionValue:"102", optionDisplay: "estmt"},
{optionValue:"11", optionDisplay: "Arif"},{optionValue:"12", optionDisplay:
"JC"}]}
is OK, too.

I presume the reason why it breaks with `"application":' is that the outer
`{...}' is regarded as delimiters of a block statement by eval(), and not as
delimiters of the Object literal notation. Hence eval()uating the variant
with `application:' yields only the Array object, which has no `application'
property. Both `"application":' and `application:' are merely regarded as
labels in a block statement there, with the former being invalid.

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16- Hide quoted text -

- Show quoted text -
Hi
I got the solution . tried without quotes and it worked fine . Thanks
to all for the help

S

Sep 27 '07 #6

P: n/a
sa******@gmail.com wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
>I presume the reason why it breaks with `"application":' is that the outer
`{...}' is regarded as delimiters of a block statement by eval(), and not as
delimiters of the Object literal notation. Hence eval()uating the variant
with `application:' yields only the Array object, which has no `application'
property. Both `"application":' and `application:' are merely regarded as
labels in a block statement there, with the former being invalid.
[...]
Please trim your quotes. http://jibbering.com/faq/
Hi
I got the solution . tried without quotes and it worked fine . Thanks
to all for the help
I don't think you have relized yet that you are shooting yourself in the
foot. As I have pointed out, because of the block statement - object
literal and property name - label ambiguities, `jsonOBJ.application.length'
may or may not work with unquoted `application', depending on the script
engine that compiles this. You should use JSON.parse() instead.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Sep 27 '07 #7

P: n/a
On Sep 27, 2:45 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
saril...@gmail.com wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
I presume the reason why it breaks with `"application":' is that the outer
`{...}' is regarded as delimiters of a block statement by eval(), and not as
delimiters of the Object literal notation. Hence eval()uating the variant
with `application:' yields only the Array object, which has no `application'
property. Both `"application":' and `application:' are merely regarded as
labels in a block statement there, with the former being invalid.
[...]

Please trim your quotes. http://jibbering.com/faq/
Hi
I got the solution . tried without quotes and it worked fine . Thanks
to all for the help

I don't think you have relized yet that you are shooting yourself in the
foot. As I have pointed out, because of the block statement - object
literal and property name - label ambiguities, `jsonOBJ.application.length'
may or may not work with unquoted `application', depending on the script
engine that compiles this. You should use JSON.parse() instead.

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
I did not use JSON.parse() as it was throwing exceptions in firefox .
But when i unquoted the 'application' , i am able to parse the
jsonOBJ . Do you have any snippets to handle JSON.parse()
exception ?

Thanks
S

Sep 27 '07 #8

P: n/a
sa******@gmail.com wrote:
I did not use JSON.parse() as it was throwing exceptions in firefox .
But when i unquoted the 'application' , i am able to parse the
jsonOBJ . Do you have any snippets to handle JSON.parse()
exception ?
try
{
ajaxRequest.responseText.parseJSON()
}
catch (e)
{
// ...
}
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Sep 29 '07 #9

P: n/a
Thomas 'PointedEars' Lahn said the following on 9/29/2007 9:16 AM:
sa******@gmail.com wrote:
>I did not use JSON.parse() as it was throwing exceptions in firefox .
But when i unquoted the 'application' , i am able to parse the
jsonOBJ . Do you have any snippets to handle JSON.parse()
exception ?

try
Error prone on the web.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 29 '07 #10

P: n/a
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 9/29/2007 9:16 AM:
>sa******@gmail.com wrote:
>>I did not use JSON.parse() as it was throwing exceptions in firefox .
^^^^^^^^^^^^^^^^^^^
>>But when i unquoted the 'application' , i am able to parse the
jsonOBJ . Do you have any snippets to handle JSON.parse()
exception ?
try

Error prone on the web.
Because of NN/IE 4.x?

It adds no more error-proneness here because -- surprise, surprise! -- the
current JSON parser implementation in J(ava)Script already uses `throw' to
throw the aforementioned exception:

http://www.json.org/js.html

The incompatibility with try...catch in ECMAScript < 3 implementations can
be worked around proprietarily with window.onerror and eval(), though.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Sep 30 '07 #11

P: n/a
Thomas 'PointedEars' Lahn said the following on 9/30/2007 5:02 AM:
Randy Webb wrote:
>Thomas 'PointedEars' Lahn said the following on 9/29/2007 9:16 AM:
>>sa******@gmail.com wrote:
I did not use JSON.parse() as it was throwing exceptions in firefox .
^^^^^^^^^^^^^^^^^^^
>>>But when i unquoted the 'application' , i am able to parse the
jsonOBJ . Do you have any snippets to handle JSON.parse()
exception ?
try
Error prone on the web.

Because of NN/IE 4.x?
Are you saying that you believe that NN4.x and IE4.x are the only
browsers potentially being used that don't support try/catch? try/catch
is error prone on the web.
It adds no more error-proneness here because -- surprise, surprise! -- the
current JSON parser implementation in J(ava)Script already uses `throw' to
throw the aforementioned exception:
That doesn't make try/catch/throw any less error prone.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 30 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.