servlet中使用gson把Vector的内容变成了一个json字符串,js中应该如何解析呢?

servlet中使用gson把Vector的内容变成了一个json字符串,js中应该如何解析呢?

问题描述:

 [{"name":"Abzu","goodid":"A0001","description":"save the sea , find the secret","price":36.0,"picture":"image/Abzu.jpg"},{"name":"Skyrim","goodid":"A0002","description":"kill the evil dragon , save the human","price":64.0,"picture":"image/Skyrim.jpg"},{"name":"DarkSoul","goodid":"A0003","description":"be the undead , find the secret","price":126.0,"picture":"image/DarkSoul.jpg"}]

最后得到了一个这样的字符串,我希望在js中解析这个字符串,然后把内容都展现在html页面上,但是应该如何做呢?这个转换的是一个带类型的Vector,属性只有字符串和数字。

前台的javascript代码,有两种方法将json转换为js中的对象和数组
var str = 你的json字符串;
var temp1 = JSON.parse(str); //方法1
var temp2 = eval("("+str+")"); //方法2
console.info(temp1);
console.info(temp2);
希望能帮到你!!!