如何检索Java中的数组值? [英] How to retrieve Array values in Java?

查看:137
本文介绍了如何检索Java中的数组值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Java应用程序中,我得到了像Array这样的Request参数。

 < script type =text / javascript> ; 
var names = new Array(); $ b $ .ajax({
url:Result,
type:'POST',
data:{
names:JSON.stringify(names) ,
globalClassId:globalClassId
}});
< / script>

现在我在java中获取这个请求参数并正确地检索值。

  //获取每个添加的用户名称[] 
for(String id:names){
--- -
-----
}

但是在java边我'获取值 names = [[1000]] ,并在for循环中获得 id = [value1]

如何删除这个额外的括号在我的字符串 [1000] 这是原始值,但我想只有 1000



请帮我解释一下它们在Array中的错误声明。我们可以使用names.join(),这将返回。 数组,

所以我们ca ñ轻松发送请求属性,如字符串 @RequestParam(names)字符串名称



现在使用循环我们很容易得到像.. ..

$ $ p $ //获取每个添加的用户使用名称[
for(String id: names.split(,)){
----------
}


In my Java Application i'm getting Request parameter like Array

<script type="text/javascript">
   var names = new Array();
    $.ajax({
        url : "Result",
        type : 'POST',
        data : {
            "names" : JSON.stringify(names),
            "globalClassId" : globalClassId
        }});
</script>

Now i'm getting this request parameter in java and retrieve the values correctly..

//Get the each added user using names[]
    for (String id : names) {
        -----
                    -----
    }

But in java side i'm getting values names=[["1000"]] and in for loop i'm getting id=["value1"]

if we pass this value to database for example select query,But it is giving null value.. even we pass correct value but we are getting null value.

How to remove this extra brackets in my String ["1000"] this is original value but i want only 1000.

Please help me is their any wrong declaration in Array.

解决方案

instead of JSON.stringify(names) we can use names.join() this will be return Array,

so we can easily send request attribute like string @RequestParam("names") String names

and now using for loop we easily get values like..

//Get the each added user using names[]
    for (String id : names.split(",")) {
        ----------
    }

这篇关于如何检索Java中的数组值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆