André
André

Reputation: 2142

Different UTF-8-Handling of Ext.JSON.encode() and Chrome's JSON.stringify()

I found a difference between Ext JS's (Version 4.1) Ext.JSON.encode() and Chrome's (Version 21.0.1180.79) JSON.stringify() when used in Chrome's console:

JSON.stringify({"title": "ä"})
> "{"title":"ä"}"

Ext.JSON.encode({"title": "ä"})
> "{"title":"\u00e4"}"

Since I want to show the results in the browser, I prefer Chrome's result, but I know that I cannot really rely on Chrome's JSON handling in other browsers. So how can I achieve Chrome's result with Sencha's Ext JS?

Upvotes: 3

Views: 5020

Answers (2)

Dionysius
Dionysius

Reputation: 498

You need to know that the value is the same. \u00e4 is the real utf-8 representation of the character ä. Chrome may output the ä decoded for better user expirience, but when decoding, both values are same:

JSON.stringify({"title": "ä"})
> "{"title":"ä"}"
Ext.JSON.encode({"title": "ä"})
> "{"title":"\u00e4"}"
JSON.parse('{"title":"ä"}')
> Object {title: "ä"}
Ext.JSON.decode('{"title":"\u00e4"}')
> Object {title: "ä"}
JSON.parse('{"title":"\u00e4"}')
> Object {title: "ä"}
Ext.JSON.decode('{"title":"ä"}')
> Object {title: "ä"}

Upvotes: 1

ypan
ypan

Reputation: 173

You can set Ext.USE_NATIVE_JSON to true in Extjs 4.

Upvotes: 5

Related Questions