Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#5774 closed bug (invalid)

$.getJSON does not work as before

Reported by: Jessige Owned by:
Priority: major Milestone: 1.4
Component: ajax Version: 1.4a2
Keywords: JSON Cc:
Blocked by: Blocking:

Description

The server returns data likes {text: "test"} in my application, $.getJSON works well in 1.3.2, but not in 1.4a2, an error occured instead.

The reason is - The line 4868~4875 of jquery-1.4a2.js:

// Get the JavaScript object, if JSON is used.
if ( type === "json" ) {
    if ( typeof JSON === "object" && JSON.parse ) {
        data = JSON.parse( data );
    } else {
        data = (new Function("return " + data))();
    }
}

I think {text: "test"} is not illegal, whatever, the two ways have different behaviors: if I make JSON = null, or I use Firefox2 or some other browsers, my application works well.

Change History (2)

comment:1 Changed 10 years ago by dmethvin

Resolution: invalid
Status: newclosed

I think {text: "test"} is not illegal

Yes it is, read the spec: http://json.org

I think you meant {"text": "test"} instead.

Some implementations may parse it, but it is still invalid.

Feel free to first read and then comment here, there is some discussion about whether to allow broken JSON to be parsed.

http://groups.google.com/group/jquery-dev/browse_thread/thread/c70e0ceece63da01/

comment:2 in reply to:  1 Changed 10 years ago by Jessige

Replying to dmethvin: Yeah, some implementations parse it - almost all the browsers, that is why the two ways have different behaviors in them. I think the loose rule is better although it is invalid. And maybe it is VALID in Javascript, Javascripters always code like this:

var something = {

element1: "something", element2: "something"

};

So does JQuery, except the element name like this "ele-ment" or "null", that is Javascripters' habit. If they can not do that in JSON(maybe only in Firefox), they will be surprised, whatever, I will be surprised. So, could you think over it?

Note: See TracTickets for help on using tickets.