日期:2014-05-16  浏览次数:20430 次

Json的一个应用例子
1、首先一个js对象函数 
//查询条件对象
     function queryCondition(custId, custName, oneNumber, simulateId, cardType, cardId, addr, vipGrade, custType, icId)
     {
     this.custId = custId;
     this.custName = custName;
     this.oneNumber = oneNumber;
     this.simulateId = simulateId;
     this.cardType = cardType;
     this.cardId = cardId;
     this.addr = addr;
     this.vipGrade = vipGrade;
     this.custType = custType;
     this.icId = icId;
     }
2、注意引入json2.js    http://www.JSON.org/json2.js
var jsonStr = new queryCondition(custIdVal, custNameVal, oneNumberVal,simulateIdVal ,cardTypeVal ,cardIdVal ,addrVal ,vipGradeVal, custTypeVal, icIdVal);
var url = "...../qryember.action?queryCondition="+JSON.stringify(jsonStr);
用ajax请求这个url
3、在Action中 import org.json.JSONObject;
JSONObject queryCondition = new JSONObject(queryCond);
String sr = queryCondition.getString("custId");

即可。

对传输很多数据时很方便。


由java对象转为 json
JSONArray json = JSONArray.fromObject(companyRadialRecordList);