how to create multiple json objects in jsp?

I wrote jsp functions to list all file names and all sub-folder names in a directory,and I want to save the result in json object.In the first step, I recursively read the all file names and all sub-folder names,and I saved the results in a string:

resdata ="myreport3.rptdesign&myreport4.rptdesign&28.12.2015$myreport.rptdesign&myreport1.rptdesign&myreport2.rptdesign&30.12.2015$customerst.rptdesign&TopNPercent.rptdesign&22.12.2015$bysupML.rptdesign&chartcwong.rptdesign&HTML5 Chart.rptdesign&23.12.2015$mainpage.rptdesign&myreport.rptdesign&myreport18.rptdesign&myreport19.rptdesign&myreport20.rptdesign&myreport21.rptdesign&myreport22.rptdesign&myreport23.rptdesign&myreport24.rptdesign&postgreSQL.rptdesign&test.rptdesign&TopNPercent.rptdesign&PathFindReport"

In the second step, I wrote the following code to write the result data into json oject:

JSONObject jsonobj=new JSONObject(); JSONArray objarray = new JSONArray(); String[] firstresd = resdata.split("[$]"); for( int i = 0 ; i < firstresd.length ; i ++ ) { String[] secondresd = firstresd[i].split("[&]"); int idfolder = secondresd.length-1; for( int j = 0 ; j < idf ; j ++ ) { jsonobj.put("parent",secondresd[id_folder]);

jsonobj.put("child",secondresd[j]); objarray.add( jsonobj); } } out.println(objarray);

But, I only got the repeating of only one same json object. The printed result is as follows:

[{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"},{"parent":"PathFindReport","child":"TopNPercent.rptdesign"}]

Could you give me some suggestions to correct my code ,please ? thanks a lot in advance .

You're asking a question about JSP in a Phalcon forum, which is a framework for PHP, written in Zephir. You're probably barking up the wrong tree. Look for a JSP specific forum.