js解析后台json数据

adonislu 2020-06-02

List<Map<String, String>> jsonArray = new ArrayList<Map<String,String>>();
        for(TSUser tsUser:userList){
            Map<String, String> map = new HashMap<String, String>();
            map.put("id", tsUser.getId());
            map.put("name", tsUser.getRealName());
            jsonArray.add(map);
        }
        return JSON.toJSONString(jsonArray);

这是后台返回的json数据

function (json) {
                alert(json) 
                var obj = eval(‘(‘ + json + ‘)‘);

这是前台接收到之后,需要用  

eval(‘(‘ + json + ‘)‘);

来解析

数据样式:

[{"id":"4028ac00727295b0017273d24d090042","name":"user021111"},{"id":"4028c013640c200f01640c3029a4001e","name":"测试用户一"}]

相关推荐