日期:2014-05-20  浏览次数:20710 次

json转换遍历问题(初学者)
public void getTeacherAreaList() throws Exception {
StringBuffer responseString = new StringBuffer();
try {
Map<String, Object> map = BeanUtil.convertToParamsMap(permissionSetModel);
List<Object> list = permissionSetBusiness.getTeacherAreaList(map); 
JSONArray jsonArray = JSONArray.fromObject(list);
此处jsonArray 内容是:[{"useremail":"222","userid":"220100000043","userloginname":"22","username":"222","userpassword":null,"usersex":"0","usertype":"2"},{"useremail":"111","userid":"220100000041","userloginname":"11","username":"111","userpassword":null,"usersex":"0","usertype":"2"},{"useremail":"222","userid":"220100000044","userloginname":"222","username":"22","userpassword":null,"usersex":"0","usertype":"2"}]
responseString.append("{\"data\":")
.append(jsonArray)
.append("}");
} catch (CommonException e) {
}
responseWriter(responseString.toString());
}
我想遍历jsonArray 里边的数据,如果usertype是2的进行其他处理,其余不做处理,我应该怎么做。试了半天没成功,求高手指点。

------解决方案--------------------
JScript code

    function aaa(){
        var jsonArray = [{"useremail":"222","userid":"220100000043","userloginname":"22","username":"222","userpassword":null,"usersex":"0","usertype":"1"},{"useremail":"111","userid":"220100000041","userloginname":"11","username":"111","userpassword":null,"usersex":"0","usertype":"2"},{"useremail":"222","userid":"220100000044","userloginname":"222","username":"22","userpassword":null,"usersex":"0","usertype":"3"}];
        for(var i = 0; i<jsonArray.length; i++){
            if(jsonArray[i].usertype == "2"){
                alert("处理");
            }
        }
    }

------解决方案--------------------
探讨
JScript code

function aaa(){
var jsonArray = [{"useremail":"222","userid":"220100000043","userloginname":"22","username":"222","userpassword":null,"usersex":"0","usertype":"1"},{"usere……