下載與學習JSON的類庫的圖記錄
作者:佚名
今天本文就來說說在C和C++上如何來讀取JSON。實際上寫入JSON的類庫是比較簡單的,難點在于讀取。另外,以QT為例,這樣比較方便敘述。
如果各位人兄已經看完了本文章,您可能已經發現了一個共同點, 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;
- }
【編輯推薦】
責任編輯:chenqingxiang
來源:
計世網