| Summary: | [Help] Web API JSON format should be encoded | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Chris Austin <ChrisAustin> | ||||
| Component: | User Assistance | Assignee: | platform-ua-inbox <platform-ua-inbox> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | cgold, ChrisAustin, snehpaul | ||||
| Version: | 3.7 | Flags: | cgold:
review+
|
||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows 7 | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
Created attachment 195255 [details]
JSON Fixes
Adding Snehasish's patch.
The patch looks good - values are encoded. However, the decode function described only decodes a handful of characters. Many other special characters are encoded in the return data, so you need to decode all of them for an accurate read. (In reply to comment #2) > The patch looks good - values are encoded. However, the decode function > described only decodes a handful of characters. Many other special characters > are encoded in the return data, so you need to decode all of them for an > accurate read. Sorry - missed the last line: return decodeURIComponent(str); If decodeURIComponent(str) takes care of the rest of the special characters, I think we may be all set. Patch looks good to me also, committed to HEAD. |
Sometimes JSON data values contains a value with some special characters, which are a part of JSON structure. Then client JSON parser not able to read JSON correctly. Now all value field's are encode using the JAVA encoding: java.net.URLEncoder.encode(val, "UTF-8") All web Client should decode the values while reading JSON data using the custom JavaScript decode method: decode = function(str) { str = '' + str; str = str.replace(/\+/g, " "); str = str.replace(/%7E/g, "~"); str = str.replace(/%21/g, "!"); str = str.replace(/%27/g, "'"); str = str.replace(/%28/g, "("); str = str.replace(/%29/g, ")"); return decodeURIComponent(str); } And Java client should use: java.net.URLDecoder.decode(val, "UTF-8")