简体   繁体   English

在php中发布解码Ajax发布的问题

[英]Issue decoding ajax post in php

I am trying to decode an array of objects that I made in javascript and sent to php however, I cant seem to decode it correctly. 我正在尝试解码在javascript中制作并发送到php的对象数组,但是,我似乎无法正确解码。 The array with an object looks like this: 带有对象的数组如下所示: 在此处输入图片说明

the php code that I am using to get the information is this: 我用来获取信息的php代码是这样的:

$allInformation = $_POST['information'];

//this works
$user = $allInformation[count($allInformation)-2];
$num = $allInformation = [count($allInformation)-1];
//this doesnt work 
$array = var_dump(json_decode($allInformation));

The index of array 1 and 2 work just fine, however, I cant seem to decode index 0 which is the object. 数组1和2的索引工作正常,但是,我似乎无法解码作为对象的索引0。 How may I go about this? 我该怎么办?

got it to work, the array to php which was JSON stringified was [{"user":"user","date":"03/17/2017"},"user",134997] and i did $update = json_decode($_POST['information']); 使它起作用,以JSON字符串化的php数组为[{“ user”:“ user”,“ date”:“ 03/17/2017”},“ user”,134997],我做了$ update = json_decode ($ _POST [ '信息']); and then looped it to get user and date as obejcts ie $update[$i]->date . 然后将其循环以获取用户和日期,即$ update [$ i]-> date。 thanks all 谢谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM