JSON object not parsing in firefox

S

saril.ks

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.optionValue ;
value = jsonOBJ.application.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
 
D

David Mark

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.optionValue ;
value = jsonOBJ.application.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?
 
S

saril.ks

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.optionValue ;
value = jsonOBJ.application.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

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
 
D

David Mark

On Sep 27, 1:57 pm, (e-mail address removed) 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.optionValue ;
value = jsonOBJ.application.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?
 
T

Thomas 'PointedEars' Lahn

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"}]}

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.
jsonOBJ has no properties
[Break on this error] len = jsonOBJ.application.length ;

Because jsonOBJ would have the value `undefined' if the evaluation failed,
if that.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
[...] 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.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
Thomas said:
[...] 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
 
S

saril.ks

Thomas said:
Thomas said:
(e-mail address removed) 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
 
T

Thomas 'PointedEars' Lahn

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
 
S

saril.ks

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
 
T

Thomas 'PointedEars' Lahn

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
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 9/29/2007 9:16 AM:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,629
Members
45,330
Latest member
AlvaStingl

Latest Threads

Top