HashMap returned by JSON in JS

 

JSP

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
   <!-- <%@ taglib prefix="s" uri="/struts-tags" %> -->
   <%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<script src="jquery.min.js" type="text/javascript"></script>
<script src="jquery-ui.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="jquery-ui.css" type="text/css" />
<script src="js/myJS.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>

JS

$(document).ready(function(){
    initPage();
    initFunctions();
});

function initPage(){
}

function globalOperation(url,param,successOperationName,failOperationName){
    $.ajax({
        type:"POST",
        url:url,
        data:param,
        success:function(data){
            if(data.status){
                if(data.status.code==200){
                    clearTipMessage();
                    successOperationName(data);
                }else{
                    failOperationName(data);
                }
            }else{
                alert("data.status has no value!Please check the action!");
            }
        },
        dataType:"json"
    });
}

function clearTipMessage(){
    $("#div_sys_msg").text("");
}
function fail_global(data){
    alert("data.status.msg");
    $("#div_sys_msg").text(data.status.msg);
}

function initFunctions()
{
    // HashMap-type data is returned.
    globalOperation("myHashMap.action", "", myHashMapSuc, fail_global);
}

function myHashMapSuc()
{
    if (null == arguments[0].myHashMapData)
    {
        alert("There is no myHashMapData data in the database.");
    }
   
    var myHashMapKeysLoc = arguments[0].myHashMapData;
    var myHashMapKeys = Object.keys(myHashMapKeysLoc);
   
    for (var i = 0; i<myHashMapKeys.length; i++)
    {
        var keyValue = myHashMapKeys[i];
        if (true == myHashMapKeysLoc.hasOwnProperty(keyValue))
        {
            var item = myHashMapKeysLoc[keyValue];
            for (var j = 0; j<item.length; j++)
            {
                var sla = item[j].sla;
            }
        }
    }
    return;
}

 

Action

    public String myHashMap()
    {
        try
        {
            if (null == myHashMapData)
            {
                myHashMapData =    new HashMap<String, List<Metrics>>();
            }

            myHashMapData.clear();
            int listNum = 1;
            for (int i = 97; i < 97+5; i++)
            {
                List<Metrics> data = new ArrayList<Metrics>();
                for (int j = 0; j<listNum; j++)
                {
                    Metrics ffData = new Metrics(new BigDecimal((double)j/listNum),new BigDecimal((double)j/listNum),new BigDecimal((double)j/listNum),
                            new BigDecimal((double)j/listNum),new BigDecimal((double)j/listNum));
                    data.add(ffData);
                }
                char[] asciiChar = {(char)i};
                myHashMapData.put(new String(asciiChar), data);
                listNum++;
            }
            status.setCode(Status.CODE_SUCCESS);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return SUCCESS;
      
    }

 

json returned:

Response:

{
"myHashMapData":
{
"d":[{"data04":0,"data03":0,"rla":0,"sla":0,"data02":0},     {"data04":0.25,"data03":0.25,"rla":0.25,"sla":0.25,"data02":0.25},{"data04":0.5,"data03":0.5,"rla":0.5,"sla":0.5,"data02":0.5},{"data04":0.75,"data03":0.75,"rla":0.75,"sla":0.75,"data02":0.75}],
"e":[{"data04":0,"data03":0,"rla":0,"sla":0,"data02":0},{"data04":0.200000000000000011102230246251565404236316680908203125,"data03":0.200000000000000011102230246251565404236316680908203125,"rla":0.200000000000000011102230246251565404236316680908203125,"sla":0.200000000000000011102230246251565404236316680908203125,"data02":0.200000000000000011102230246251565404236316680908203125},{"data04":0.40000000000000002220446049250313080847263336181640625,"data03":0.40000000000000002220446049250313080847263336181640625,"rla":0.40000000000000002220446049250313080847263336181640625,"sla":0.40000000000000002220446049250313080847263336181640625,"data02":0.40000000000000002220446049250313080847263336181640625},{"data04":0.59999999999999997779553950749686919152736663818359375,"data03":0.59999999999999997779553950749686919152736663818359375,"rla":0.59999999999999997779553950749686919152736663818359375,"sla":0.59999999999999997779553950749686919152736663818359375,"data02":0.59999999999999997779553950749686919152736663818359375},{"data04":0.8000000000000000444089209850062616169452667236328125,"data03":0.8000000000000000444089209850062616169452667236328125,"rla":0.8000000000000000444089209850062616169452667236328125,"sla":0.8000000000000000444089209850062616169452667236328125,"data02":0.8000000000000000444089209850062616169452667236328125}],
"b":[{"data04":0,"data03":0,"rla":0,"sla":0,"data02":0},{"data04":0.5,"data03":0.5,"rla":0.5,"sla":0.5,"data02":0.5}],
"c":[{"data04":0,"data03":0,"rla":0,"sla":0,"data02":0},{"data04":0.333333333333333314829616256247390992939472198486328125,"data03":0.333333333333333314829616256247390992939472198486328125,"rla":0.333333333333333314829616256247390992939472198486328125,"sla":0.333333333333333314829616256247390992939472198486328125,"data02":0.333333333333333314829616256247390992939472198486328125},{"data04":0.66666666666666662965923251249478198587894439697265625,"data03":0.66666666666666662965923251249478198587894439697265625,"rla":0.66666666666666662965923251249478198587894439697265625,"sla":0.66666666666666662965923251249478198587894439697265625,"data02":0.66666666666666662965923251249478198587894439697265625}],
"a":[{"data04":0,"data03":0,"rla":0,"sla":0,"data02":0}]
},

"status":{"code":200,"msg":""}
}

Json:

posted @ 2012-12-31 17:42  lizmy  阅读(262)  评论(0编辑  收藏  举报