我无法将我的数组列表的值放在我的jsonObjectReturn中

时间:2016-10-10 03:41:40

标签: java arrays arraylist

我试图将我的数组列表中的值放到我的jsonObjectReturn中,但是我无法将其放入。它只返回0值。这是我的代码段:

List<String> values = new LinkedList<String>();

        jsonObjectReturn =  JSONFactoryUtil.createJSONObject();

        for (int i = 4; i <= 27; i++) {
            values.add(callableStatement.getString(i));
            ..//I'm getting the values here..

        }

        System.out.println("The list: " + values.toString());

此输出列表:[118708139,I,,LABRAMONTE,JESUS,CALUMPIANO,000,127,MAYON ST ,,, QUEZON CITY ,,,000,033,00003 ,,,,, A ,C,R,0]

        for (String element: values){
            jsonObjectReturn.put("tpTin", element);
            jsonObjectReturn.put("tpClsfCode",  element);
            jsonObjectReturn.put("tpRegisteredName",  element);
            jsonObjectReturn.put("tpLname",  element);
            jsonObjectReturn.put("tpFname",  element);
            jsonObjectReturn.put("tpMname",  element);
            jsonObjectReturn.put("tpaBranchCode",  element);
            jsonObjectReturn.put("tpaSubstreet",  element);
            jsonObjectReturn.put("tpaStreet",  element);
            jsonObjectReturn.put("tpaBarangay",  element);
            jsonObjectReturn.put("tpaDistrict",  element);
            jsonObjectReturn.put("tpaCity",  element);
            jsonObjectReturn.put("tpaZipCode",  element);
            jsonObjectReturn.put("tplBranchCode",  element);
            jsonObjectReturn.put("tplRdoCode",  element);
            jsonObjectReturn.put("tplMunCode",  element);
            jsonObjectReturn.put("tplContactLname",  element);
            jsonObjectReturn.put("tplContactFname",  element);
            jsonObjectReturn.put("tplContactMname",  element);
            jsonObjectReturn.put("tplContactTelno",  element);
            jsonObjectReturn.put("tpStatus",  element);
            jsonObjectReturn.put("tpaStatusCode",  element);
            jsonObjectReturn.put("tpaRegisterFlag",  element);
            jsonObjectReturn.put("oTin",  element);

            System.out.println("test " + element);


        }
        System.out.println("The list2: " +jsonObjectReturn);

测试的输出是测试118708139 测试我
测试
测试LABRAMONTE
测试耶稣
测试CALUMPIANO
测试000
测试127
测试MAYON ST
测试
测试
测试QUEZON CITY
测试
测试000
测试033
测试00003
测试
测试
测试
测试
测试A
试验C
试验R
测试0
list2的输出是 list2:{&#34; tpaDistrict&#34;:&#34; 0&#34;,&#34; tpaBranchCode&#34;:&#34; 0&#34;,& #34; tpaStreet&#34;:&#34; 0&#34;&#34; tpaRegisterFlag&#34;:&#34; 0&#34;&#34; tpaStatusCode&#34;:&#34; 0&# 34;,&#34; tplContactFname&#34;:&#34; 0&#34;&#34; tpClsfCode&#34;:&#34; 0&#34;&#34; oTin&#34;:&# 34; 0&#34;&#34; tpFname&#34;:&#34; 0&#34;&#34; tpaCity&#34;:&#34; 0&#34;&#34; tplRdoCode&#34 ;:&#34; 0&#34;&#34; tpaBarangay&#34;:&#34; 0&#34;&#34; tpTin&#34;:&#34; 0&#34;&#34 ; tplContactMname&#34;:&#34; 0&#34;&#34; tpRegisteredName&#34;:&#34; 0&#34;&#34; tpMname&#34;:&#34; 0&#34; &#34; tpaZipCode&#34;:&#34; 0&#34;&#34; tplBranchCode&#34;:&#34; 0&#34;&#34; tpStatus&#34;:&#34; 0&#34;&#34; tpaSubstreet&#34;:&#34; 0&#34;&#34; tplContactTelno&#34;:&#34; 0&#34;&#34; tplMunCode&#34 ;: #&34; 0&#34;&#34; tplContactLname&#34;:&#34; 0&#34;&#34; tpLname&#34;:&#34; 0&#34;} < / p>

现在,我想要发生的是将&#34; test&#34;的值放在在我的jsonObjectReturn里面。我试着把它放在forloop中,但我只能得到&#34; 0&#34;作为价值观。感谢

1 个答案:

答案 0 :(得分:0)

你的for..each循环是罪魁祸首。它实际上最终会将你的JSON的最后一个元素(为零)设置为你所有的jsonObjectReturn个键

因为订单是预先确定的(我想是因为您使用的是LinkedList),所以只需使用它来设置jsonObjectReturn值:

jsonObjectReturn.put("tpTin", values[0]);
jsonObjectReturn.put("tpClsfCode", values[1]);
// and so on..