如果各位人兄已经看完了本文章,您可能已经发现了一个共同点, encodeURI(encodeURI(fontname)),这就是解决问题的方法了,那么就可以进行试试了,希望对您有所帮助,下面就开始对JSON的类库学习吧。
因为我用JAVA开发,所以首先去要下载JSON的类库,我用的是http://www.sf.net提供的json类库。而json类库以信赖于几个其它的类库,JSON的类库下面把所需要的类截个图记录。
写服务器商程序,返回一个JSON格式的数据:
- package cn.limaoyuan.jquery.xml;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- public class JqueryServletForXml extends HttpServlet {
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- System.out.println("into JqueryServletForXml");
- response.setContentType("text/xml");
- response.setCharacterEncoding("gbk");
- String xml = "<?xml version=\"1.0\" encoding=\"gbk\"?><userlist>" +
- "<user><name>limy_1</name><age>25_1</age></user>" +
- "<user><name>limy_2</name><age>25_2</age></user>" +
- "<user name=\"limy_3\" age=\"25_3\"></user>" +
- "<user name=\"limy_4\" age=\"25_4\"></user></userlist>";
- response.getWriter().println(xml);
- }
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- doGet(request, response);
- }
- }
- 3.其中需要一个User类
- package cn.limaoyuan.jquery.json;
- public class User {
- private String name;
- private int age;
- private String address;
- private String phone;
- private String mobile;
- public String getAddress() {
- return address;
- }
- public void setAddress(String address) {
- this.address = address;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public String getMobile() {
- return mobile;
- }
- public void setMobile(String mobile) {
- this.mobile = mobile;
- }
- public String getName() {
- return name;
- }
【编辑推荐】