jsonデータを文字列に分割する方法に疑問があります。私の意図は、いくつかのテキストボックスを動的に作成し、ajax投稿を使用して投稿することです。完全なポストバックを避けるために、ここで私のajax部分を確認してください
function profileAndSectin_Submit() {
//alert('test123');
document.getElementById("hiddenSection").value = i;
$('#profile_form').submit(
function() {
alert(i);
var profileName = $('#profileName').val();
var Section1 = $('#Section1').val();
var dynamicData = " ";
for ( var m = 2; m <= i; m++) {
var textbx = $('#Section' + m).val();//"Section"+m;
var dt="section"+m+":"+textbx;
//var txtbxval = document.getElementsByName(textbx).value;
var x = textbx ;
if (m <= m - 1) {
x + " ";
}
dynamicData = dynamicData +dt+",";
//dynamicData = dynamicData +":"+dt+",";
}
alert(dynamicData);
var Data = "profileName :"+profileName+","+"Section1 :"+Section1+"," + dynamicData;
alert(Data);
$.ajax({
type : "post",
url : "addProfile",
//data : {
//"profileName" : profileName,
//"Section1" : Section1,
//},
data :{"Count" : i,"Data" :Data},
success : function(msg) {
alert(i);
$('#divContent').load('addfields.jsp');
},
Error : function(msg) {
debugger;
}
});
return false;
});
};
そして、これらの値を1つのコントローラーに送信しています。主な問題はここにあります。@RequestParam("Data")
文字列データを使用している場合、これらのデータを取得するにはどうすればよいですか?
{ProfileName:profileName,Section1:section1,Section2:section2...}
しかし、私は profileName 、Section2 および Section3 のような各文字列が必要です。
コントローラー.java
@Controller
public class SettingController implements HibernateConfig {
@RequestMapping(value = "/addProfile", method = RequestMethod.POST)
//public String home(HttpServletRequest request,@RequestParam("Count") int i,@RequestParam("profileName") String pname,@RequestParam("Section1") String Section1,Locale locale, Model model) throws IOException
public String home(HttpServletRequest request,@RequestParam("Count") int i,@RequestParam("Data") String data,Locale locale, Model model) throws IOException
{
System.out.println(i);
System.out.println(data);
}
アイデアはありますか?