XStream类对象把List<javaBean>()转成json数据
【省市联动】
Servlet端:
XStream把list转成json数据 //JSONArray-->变成数组/集合[] //JSONObject-->变成简单的数据{name:ayee, pid:1} JSONArray jsonArray = JSONArray.fromObject(list); String json = jsonArray.toString();
js端:
$(function(){ $("#province").change(function(){ var pids = $(this).val(); /*[ { "cname":"福州市", "id":1, "pid":1 }, { "cname":"厦门市", "id":2, "pid":1 }, ... ]*/ $.post("CityServlet",{pid:pids}, function(data,status){ $("#city").html("<option value=‘‘>-请选择-</option>"); $(data).each(function(index, c){ // alert(c.cname); $("#city").append("<option value=‘" + c.id + "‘>" + c.cname + "</option>") }); },"json"); }); });
Json相关jar包:
commons-beanutils.jar
commons-collections.jar
commons-lang.jar
commons-logging.jar
ezmorph.jar
json-lib-2.4-jdk15.jar
相关推荐
somebodyoneday 2020-06-15
adonislu 2020-06-02
baijinswpu 2020-02-19
adonislu 2020-02-14
83163452 2020-01-28
adonislu 2020-01-10
baijinswpu 2020-01-01
adonislu 2019-12-31
xufankang 2019-12-19
somebodyoneday 2019-12-07
abcx 2015-05-25
somebodyoneday 2019-10-30
newthon 2019-10-21
ZCMUCZX 2016-04-14
iovaaron 2015-04-10
Dolphinsz 2016-04-25
revivre 2017-09-07