我已在表单提交时将序列化数据发送给PHP:
<#import "/spring.ftl" as spring>
<html>
<body>
Welcome
<!-- For login user -->
<@spring.url '/logout' var="logoutUrl"/>
<form action="${logoutUrl}" method="post" id="logoutForm">
<input type="hidden" name="${_csrf.parameterName}"
value="${_csrf.token}" />
</form>
<script>
function formSubmit() {
document.getElementById("logoutForm").submit();
}
</script>
<#if "${pageContext.request.userPrincipal.name != null}"?? >
<span><h2>
User : ${pageContext.request.userPrincipal.name} | <a
href="javascript:formSubmit()"> Logout</a>
</h2></span>
</#if>
</body>
</html>
数据格式如下:
$('#new-store-pickup').on("click",function(){
var businessHoursManager = $("#businessHoursContainer3").businessHours();
$('#businesshourvalue').val(JSON.stringify(businessHoursManager.serialize()));
$('#new-product-form').submit();
return false;
});
如何在PHP中反序列化上述数据?
答案 0 :(得分:1)
<?php
$json = '[{"isActive":true,"timeFrom":"9:00","timeTill":"18:00"},{"isActive":true,"timeFrom":"9:00","timeTill":"18:00"},{"isActive":true,"timeFrom":"9:00","timeTill":"18:00"},{"isActive":true,"timeFrom":"9:00","timeTill":"18:00"},{"isActive":true,"timeFrom":"9:00","timeTill":"18:00"},{"isActive":false,"timeFrom":null,"timeTill":null},{"isActive":false,"timeFrom":null,"timeTill":null}]' ;
echo "<pre>";
$converted = json_decode($json);
print_r($converted);
?>