The test action: public class ExampleSupport extends ActionSupport {
public String getName() { //a string of chinese return "测试"; } } This action should get a json like this : {"name":"测试"}, the name property's length is 4,but json.length is 2. So the last 2 character is cutted,and I get like this:{"name":"测试,After I replace the code with "json.getBytes(getEncoding()).length", it works fine. currentUser is a ognl expression. On 3/26/07, Musachy Barroso <[EMAIL PROTECTED]> wrote:
Hi Joey Could you send me a testcase for the problem you are having, like a sample action that will break the json generation? I thought about adding parameters a while back, the problem is that the parameters work for the action, but if you have an object returned by one of the getter methods in the action, then there would be no way to control the json generation for that object. regards musachy On 3/25/07, joey <[EMAIL PROTECTED]> wrote: > > I just tried to generate json result by using Json plugin. > But I found that the result is cutted,not a well-formed json result. > After debugging ,I found the reason,one of my string property of the > struts action isn't a iso-8859-1 encoding string. > In the method "execute" of class JSONResult,you could find : > response.setContentLength(json.length); > response.setContentType("application/json;charset=" + getEncoding()); > When the json.length is smller than json.getBytes(encoding).length, > the result will be cut. > So I thought maybe it's better to change json.length to > json.getBytes(encoding).length. > Moreover,I thought it's better if I could set which property to be > serialized in the struts.xml.It could be more flexible than the > annotation. > For example: > <result type="json"> > <param name="json.includeParam">name,email</param> > </result> > -- "Hey you! Would you help me to carry the stone?" Pink Floyd