Ticket #660 (enhancement)
Opened 1 year ago
Last modified 3 months ago
Using Globalization.Charset in JSON for AJAX Callbacks
Status: closed (fixed)
| Reported by: | wastiee | Assigned to: | xue |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.1.2 |
| Component: | Prado Framework v3 | Version: | 3.1 |
| Severity: | minor | Keywords: | |
| Cc: |
The topic is here http://www.pradosoft.com/forum/index.php/topic,4491.0.html
I've talked to Wei about this.
A (long) summary: JSON uses UTF-8 internally, so JSON encoding is made using UTF-8 source (and JSON decoding is made using UTF-8 target). This prevents setting of any ActiveWidget's properties to non-UTF-8 strings. Instead, i propose using Globalization.charset to encode/decode PRADO-side strings to UTF-8 just before JSON encoding, and after JSON decoding (using the assumption "Globalization.charset denotes application's encoding")
There are two possible ways; one is to make these encoding conversion just before TJSON::encode() is called in callback handling functions, and do it after TJSON::decode() when parsing JSON-encoded input data from javascript. This fixes the problem only for AJAX callbacks. I think the more "right" method is, to put this charset conversion directly in TJSON::encode() and TJSON::decode(), changing these functions definitions from "strings provided to/from these functions are ALWAYS in UTF-8" to "strings provided to/from these functions are in Globalization.Charset if specified, UTF-8 otherwise".
Using the second way, not only AJAX callbacks can be handled, but a JSON Service can be created with a different charset than UTF-8 using Globalization.charset
Change History
07/01/2007 06:11:30 AM: Modified by wastiee
07/16/2007 12:48:52 PM: Modified by xue
- milestone set to 3.1.1.
09/25/2007 07:08:38 PM: Modified by wastiee
here's the patch for prado/framework/Web/Javascripts/TJSON.php (the source was in 3.1.0RC, i don't know if it's changed in 3.1.0 final) Code:
148a149,152 > $globalization = Prado::getApplication()->getGlobalization(false); > if ($globalization !== null && strtoupper($globalization->getCharset()) != 'UTF-8') > $var = iconv($globalization->getCharset(), 'UTF-8', $var); > 488a493,496 > $globalization = Prado::getApplication()->getGlobalization(false); > if ($globalization !== null && strtoupper($globalization->getCharset()) != 'UTF-8') > $utf8 = iconv('UTF-8', $globalization->getCharset().'//IGNORE', $utf8); > 758c766 < ?> \ No newline at end of file --- > ?>
09/25/2007 07:09:32 PM: Modified by wastiee
the patch showed mixed up in trac, see the forum post for the patch
09/30/2007 03:27:16 PM: Modified by xue
- milestone changed from 3.1.1 to 3.1.2.
04/18/2008 12:14:17 PM: Modified by mikl
- status changed from new to closed.
- resolution set to fixed.
Fixed in [2438]. Thanks!

mispelling; not "ActiveWidget", ActiveControl? :)