java String字符串怎么转换成List,还是说先转换成json,再由json转换成list
这是在服务器上获取的String类型字符串{"code":"1","table":{"title":["单据名称","单据日期","提交人员","单据流水","帐套编号"...
这是在服务器上获取的String类型字符串
{"code":"1","table":{"title":["单据名称","单据日期","提交人员","单据流水","帐套编号","帐套名称","逻辑表名"],"value0":["采购请购单","20160124","0034","86","005","演示","CGQGD"],"value1":["采购请购单","20160123","0056","78","005","演示","CGQGD"],"value2":["采购请购单","20160123","0041","80","005","演示","CGQGD"],"value3":["采购请购单","20160122","0037","81","005","演示","CGQGD"],"value4":["采购请购单","20160122","0052","82","005","演示","CGQGD"],"value5":["采购请购单","20160122","0043","83","005","演示","CGQGD"],"value6":["采购请购单","20160124","0034","84","005","演示","CGQGD"],"value7":["采购请购单","20160126","0054","88","005","演示","CGQGD"]}}
我先把他转换成list然后发送到jsp页面,给他遍历用表格显示出来,我该怎么便利,网上转换成list的方法,我用这不行。 展开
{"code":"1","table":{"title":["单据名称","单据日期","提交人员","单据流水","帐套编号","帐套名称","逻辑表名"],"value0":["采购请购单","20160124","0034","86","005","演示","CGQGD"],"value1":["采购请购单","20160123","0056","78","005","演示","CGQGD"],"value2":["采购请购单","20160123","0041","80","005","演示","CGQGD"],"value3":["采购请购单","20160122","0037","81","005","演示","CGQGD"],"value4":["采购请购单","20160122","0052","82","005","演示","CGQGD"],"value5":["采购请购单","20160122","0043","83","005","演示","CGQGD"],"value6":["采购请购单","20160124","0034","84","005","演示","CGQGD"],"value7":["采购请购单","20160126","0054","88","005","演示","CGQGD"]}}
我先把他转换成list然后发送到jsp页面,给他遍历用表格显示出来,我该怎么便利,网上转换成list的方法,我用这不行。 展开
展开全部
服务端:
//获取数据
List<City> list = getCities();
//将数据转成JSON字符串
JSONArray jsonObj =
JSONArray.fromObject(list);
System.out.println(jsonObj);//控制台显示
String jsonStr = jsonObj.toString();
out.print(jsonStr);//给Ajax对象返回
out.close();
客户端:
var xhr = createXhr();
xhr.open("get","loadcities.do",true);
//注册回调处理
xhr.onreadystatechange = function(){
if(xhr.readyState==4&&xhr.status==200){
//获取服务器返回的信息(JSON对象数组字符串)
var data = xhr.responseText;
//将字符串转成JSON对象数组类型
var json_data = JSON.parse(data);
//循环JSON对象数组
var city_select =
document.getElementById("city");
for(var i=0;i<json_data.length;i++){
//json_data[i]表示{"id":1,"name":"北京"}
var id = json_data[i].id;//获取id值
var name = json_data[i].name;//获取name值
//创建一个<option>元素
var opt = new Option(name,id);
//添加到<select>元素中
city_select.options[i] = opt;
}
}
//获取数据
List<City> list = getCities();
//将数据转成JSON字符串
JSONArray jsonObj =
JSONArray.fromObject(list);
System.out.println(jsonObj);//控制台显示
String jsonStr = jsonObj.toString();
out.print(jsonStr);//给Ajax对象返回
out.close();
客户端:
var xhr = createXhr();
xhr.open("get","loadcities.do",true);
//注册回调处理
xhr.onreadystatechange = function(){
if(xhr.readyState==4&&xhr.status==200){
//获取服务器返回的信息(JSON对象数组字符串)
var data = xhr.responseText;
//将字符串转成JSON对象数组类型
var json_data = JSON.parse(data);
//循环JSON对象数组
var city_select =
document.getElementById("city");
for(var i=0;i<json_data.length;i++){
//json_data[i]表示{"id":1,"name":"北京"}
var id = json_data[i].id;//获取id值
var name = json_data[i].name;//获取name值
//创建一个<option>元素
var opt = new Option(name,id);
//添加到<select>元素中
city_select.options[i] = opt;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询