私は JavaScript で JSONObject を作成し、次のコードを使用して文字列としてサーブレットに送信しています。
insertDtls = function() {
var jsonObj = [];
jsonObj.push({location: this.location()});
jsonObj.push({value: this.value()});
jsonObj.push({coverage: this.coverage()});
jsonObj.push({validPeriod: this.collateralValidPer()});
jsonObj.push({description: this.description()});
var b = JSON.stringify(jsonObj);
console.log(b.toString());
$.ajax({
url:"/HDSWFHub/AppProxy",
type: 'GET',
data: $.extend({WrJOB: "insertDtls", mainData: b}, tJS.getCommonPostData()),
dataType: "json",
success: function(responseText, status, xhr){
updateViewModel(responseText);
},
error: function(jqXHR, textStatus, error){
tJS.manageError(jqXHR);
}
});
},
文字列は次のよう
[{"location":"Boston"},{"value":"5"},{"coverage":"15"},{"validPeriod":"08/05/2013"},{"description":"test description"}]
になり、サーブレットは問題なくそれを受け取ります。
次に、サーブレットでこれを取得しています:
String step = request.getParameter("mainData");
JSONObject jsonObj = new JSONObject();
final JSONObject obj = new JSONObject();
System.out.println(step);
try {
obj.put("viewModel", "index");
obj.put("WrSESSIONTICKET", sessionTicket);
response.getWriter().print(obj.toString());
} catch (final Exception e) {
logException(request, response, e, true);
}
アイテムをループできるようにするため、または必要なものを取得するために、JSON文字列をサーブレットのオブジェクトに変換しようとしています。私が使っているライブラリはorg.json
私は疲れました:
JSONObject jsonObj = new JSONObject(step);
成功せずに。このエラーが発生しました:
Unhandled exception type JSONException
何が起こっているのかわかりません。多分私はすでに疲れすぎています。本当に小さなものが欠けていると確信していますが、それを見つけることができません。
私はそれが何百回も尋ねられたことを知っています。私はたくさんの反対票を受け取ることを知っていますが、私の問題に対する答えを見つけることができませんでした.