[DUPICATE]如何通過JSON數組與Servlet
這我POST JSON代碼
var data_create = JSON.stringify($("#form_create_delegate").serializeArray());
alert("isi data_create" + data_create);
// console.log(data_create)
$.ajax({
type: "POST",
url: "formCreateDelegationServlet",
dataType: "json",
data:data:{JSONFile:data_create},
success: function (response) { }
});
這是我的結果JSON
JSONFile:[{"name":"id_form_delegate","value":"1"},{"name":"merchant","value":"AMBHARA HOTEL TERBAIK"},{"name":"citty","value":"JAKARTA PUSAT"},{"name":"addrs","value":"JL. DIPONEGORO NO. 1J"},{"name":"province_merchant","value":"DKI JAKARTA"},{"name":"mid_merchant[]","value":"1"},{"name":"tid_merchant[]","value":"1"},{"name":"mid_merchant[]","value":"2"},{"name":"tid_merchant[]","value":"2"}]
如何刪除屬性 「名」 和「價值」從我的JsonArray
我想製作一個這樣的格式
[{"merchant":"AMBHARA HOTEL TERBAIK","citty":"JAKARTA PUSAT"}]
這是我的servlet代碼
JSONArray jsonArray = (JSONArray) net.sf.json.JSONSerializer.toJSON(request.getParameter("JSONFile"));
merchant = jsonObject.getString("merchant");
city = jsonObject.getString("city");
addrs = jsonObject.getString("addrs");
province_merchant = jsonObject.getString("province_merchant");
tid = jsonObject.getString("tid_merchant");
mid = jsonObject.getString("tid_merchant");
//
System.out.println("nama_merchant: " + nama_merchant);
System.out.println("kota_merchant: " + kota_merchant);
System.out.println("alamat_merchant: " + alamat_merchant);
System.out.println("province_merchant: " + province_merchant);
System.out.println("mid: " + mid);
System.out.println("tid: " + tid);
但它不如果你想擺脫鍵,只是保留值數組,你可以使用陣列工作
,如果你刪除這兩個,你會得到空的對象。 –
你是什麼意思刪除?如果你從對象中刪除這些屬性,將不會有任何問題 –
你的問題並不清楚。也許你想要一個像這樣的數組的數組''[[「id_form_delegate」,「1」],[「merchant」,「」AMBHARA HOTEL TERBAIK「]] ...? – edc65