I'm trying to send Json text using $this_helper->json->sendJson('Ôtre'=>'Être'
but the problem is the special caracters not recongnized. how i can force zend to send appropriat Json.?
There is a problem with some PHP Versions when encoding Special chars. You can overship the problem by setting the following:
Zend_Json::$useBuiltinEncoderDecoder = true;
Related
I try to exchange Data via RadServer IIS Package and Delphi Client with EMSEndpoint.
What I try looks simple to me but I can't get it done now.
In the Package there is a TFDConnection pointing to a MSSql Server. TFDQuery is connected with that Connection.
With this code I create the JSON Response (Serverside):
var lStream: TStringStream := TStringStream.create;
FDQuery.SaveToStream(lStream,sfJSON);
AResponse.Body.SetStream(lStream,'application/json' ,True);
with that code I try to load the Dataset into TFDMemtable (Clientside):
lstrstream: TStringStream := TStringStream.create(EMSBackendEndpoint.Response.Content);
aMemtable.LoadFromStream(lstrstream, sfJSON);
The Memtable says [FireDac][Stan]-719 invalid JSON storage format
How could that be? I know where the Problem is, there are äöü Symbols in my Stream, but when I load that from one Component to the other it should work, shouldn't it?
Any suggestions what I can try? What I have tryed so far:
Loading JSON in Client over UTF8toUnicode. That let me load the Memtable but results in missing Letters like öäü
Changing UTF8toUnicode on the Serverside and backwords on the Client side. That leads to not readable JSON for the Memtable
Loading JSON into JSONString and Format it localy before loading into Memtable. That leads to not Readable JSON because also the Array and Object chars are quoted out.
JSON is most commonly exchanged using UTF-8, but by default TStringStream does not use UTF-8 on Windows, only on Posix systems. Try using TStringStream.Create(..., TEncoding.UTF8) to force UTF-8.
This assumes that FDQuery.SaveToStream() saves using UTF-8, and aMemtable.LoadFromStream() loads using UTF-8, otherwise you will still have an encoding mismatch.
I am designing a Web API which returns JSON as the content-type, the response body could contain characters like ', ", < and >, they are valid characters in JSON. So, my question is should I do HTML encode for my Web API response body or should I leave this task to HTML client who is consuming my Web API?
No; you must not.
You must only escape data if and when you concatenate it into a structured format.
If you return JSON like { "text": "Content by X & Y" }, anyone who reads that JSON will see the literal text &.
It will only work correctly for extremely broken clients who concatenate it directly into their HTML without escaping.
In short:
Never escape text except when you're about to display it
What platform are you using? For example, Node.js, you can use restify to handle that very well. You don't need to explicitly encode the data. Therefore, please find a restful framework or component to help you out.
I am getting JSON response from some web server, say the server returns:
"kən.grætju'leiʃən"
I use AFNetworking and JSONKit, but what I've received is:
"æm'biʃən"
Not sure if it's AFNetworking's problem or JSONKit's problem, but any way, how to I parse and convert the string so it looks the same as from server?
Thanks
The server may be returning characters encoded in a way that violates the official JSON spec. If those characters are encoded as escaped unicode IDs (like \U1234) then JSONKit and NSJSONSerialization should both handle them fine.
If you can't change the server, you can work around the issue by URL-decoding the string - see https://stackoverflow.com/a/10691541/1445366 for some code to handle it. But if your server isn't following the correct specs, you're likely to run into other issues.
I am building one web application using:
SPRING MVC
SPRING SECURITY
HIBERNATE
mySQL
I want to add internationalization support for Japanese language in my app.
To display label and messages from properties file in japanese language , I have made use of Spring Locale Interceptor and its working fine.
What I need , I want to store Japanese characters in Database (not in Unicode) from user inputs and want to display on page.
Also , when i enters Japanese characters in form , in POJO, it is automatically converted in unicode, how can i disable this behaviour?
To store or read characters in the database with explicitly specified encoding, use useUnicode and characterEncoding properties in your JDBC URL. see http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-charsets.html and http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-configuration-properties.html
In the 2nd question, do you mean that you want to use byte[] instead of java.lang.String when you treat input strings? I think you can do it, but I can not recommend it.
If I have the xml/html data to post we need to encode the data to avoid the XSS validation. So should we use HTMLencode or URI encoding for this.
If URI encoding is used will it cause issues as form POST automatically URI encode all the data before sending.
XSS is a problem caused by giving tainted data to the client. It can't be solved at the point where data is posted.
To protect against it, HTML encode the data (immediately) before placing it in an HTML document.
Remember: filter input, escape output.
Always filter input before placing it in a database (to avoid SQL injection etc)
Escape output before sending it to the client by filtering / encoding any HTML in the dynamic content.