如何通过javascript访问JSON数据

时间:2012-08-02 12:47:44

标签: javascript jquery jquery-ui

我想在没有应用html的情况下访问单选按钮(性别字段)中的jsongrid值。我尝试了简单的javascript函数,它在UI中工作正常,但是值来自html输入,但我希望值来自jsongrid.Plz帮助我..

这是JavaScript代码

<script type="text/javascript">
    $j.ajax({
        url:"UserGender",
        type: "GET",
        data: datasourses,
        dataType: "json",
        success: function (data){
            $.each(data, function(i, selectedItem) {
                alert("paramValue: " + selectedItem.paramValue + ", paramCode: " +    
                data.selectedItem.paramCode);
            });
        }       
    });
</script>

这是html

<input type="radio" name="Female" >
<input type="radio" name="Male" >

Json代码

{
    "jsonWrapperforGrid": {
        "page": "1",
        "total": "2",
        "rows": [
            {
                "tenantId": 0,
                "paramType": "UserGender",
                "paramCode": "F",
                "langCode": "en",
                "paramValue": "Female"
            },
            {
                "tenantId": 0,
                "paramType": "UserGender",
                "paramCode": "M",
                "langCode": "en",
                "paramValue": "Male",
                "paramBlob": ""
            }
        ]
    }
}

提前致谢

1 个答案:

答案 0 :(得分:4)

 $.each(data.jsonWrapperforGrid.rows, function() {
    alert("paramValue: " + this.paramValue + ", paramCode: " +    this.paramCode);
});