duanliaogui4133 2019-05-10 10:08
浏览 122

PHP数组代码返回json数据,如何从数组json中获取特定数据

I have an array that have values as usual in PHP. But in a field of a array there is json data and im not able to unserialize the data in order to get a specific element.

The array have a field that is named "__viewstate" that have the data i want, the data i want to get is the number "+46736506234" but im not able to unserialize the data, all I get is bool false but i guess because its wrong formated.

How could I proceed to in order to get the phonenumber from this data?:

I am using var_dump($this) to get the posted content on the confirmation page, var_dump($_POST) gives the same array.

["__viewstate"]=> string(974) "a:4:{i:0;a:1:{s:9:\"projectId\";i:4;}i:1;a:15:{s:14:\"availabilityId\";i:6;s:13:\"availableDate\";s:10:\"2019-05-29\";s:7:\"endDate\";s:10:\"2019-05-29\";s:9:\"startTime\";s:4:\"2569\";s:7:\"endTime\";N;s:13:\"startTimeslot\";s:8:\"10:30 am\";s:11:\"endTimeslot\";s:0:\"\";s:5:\"seats\";i:4;s:12:\"seatsMinimum\";i:1;s:12:\"seatsMaximum\";i:10;s:13:\"dynamicFields\";a:0:{}s:8:\"timezone\";s:16:\"Europe/Stockholm\";s:15:\"_availabilityId\";N;s:14:\"_availableDate\";N;s:8:\"_endDate\";N;}i:6;a:1:{s:9:\"requestId\";s:41:\"calendarista_req_1557482130_5cd54a92b61bd\";}i:4;a:9:{s:12:\"formelements\";a:1:{i:0;a:5:{s:9:\"projectId\";i:4;s:9:\"elementId\";i:6;s:10:\"orderIndex\";i:6;s:5:\"value\";s:10:\"+46736506234\";s:5:\"label\";s:11:\"Phonenumber\";}}s:6:\"userId\";i:0;s:4:\"name\";s:10:\"Firstname Lastname\";s:9:\"firstname\";s:5:\"Firstname\";s:8:\"lastname\";s:4:\"Lastname\";s:5:\"email\";s:13:\"info@Firstname.se\";s:12:\"customerType\";i:0;s:11:\"billingInfo\";a:0:{}s:5:\"Mobil\";N;}}"

The whole array is:


    array(14) { ["projectId"]=> string(1) "4" ["calendarMode"]=> string(1) "1" ["postbackStep"]=> string(8) "checkout" ["previewUrl"]=> string(0) "" ["__viewstate"]=> string(997) "a:4:{i:0;a:1:{s:9:\"projectId\";i:4;}i:1;a:15:{s:14:\"availabilityId\";i:6;s:13:\"availableDate\";s:10:\"2019-05-31\";s:7:\"endDate\";s:10:\"2019-05-31\";s:9:\"startTime\";s:4:\"2627\";s:7:\"endTime\";N;s:13:\"startTimeslot\";s:8:\"10:30 am\";s:11:\"endTimeslot\";s:0:\"\";s:5:\"seats\";i:4;s:12:\"seatsMinimum\";i:1;s:12:\"seatsMaximum\";i:6;s:13:\"dynamicFields\";a:0:{}s:8:\"timezone\";s:16:\"Europe/Stockholm\";s:15:\"_availabilityId\";N;s:14:\"_availableDate\";N;s:8:\"_endDate\";N;}i:6;a:1:{s:9:\"requestId\";s:41:\"calendarista_req_1557484124_5cd5525ca8249\";}i:4;a:9:{s:12:\"formelements\";a:1:{i:0;a:5:{s:9:\"projectId\";i:4;s:9:\"elementId\";i:6;s:10:\"orderIndex\";i:6;s:5:\"value\";s:11:\"96146734834\";s:5:\"label\";s:11:\"Phonenumber\";}}s:6:\"userId\";i:0;s:4:\"name\";s:17:\"Firstname Lasname\";s:9:\"firstname\";s:9:\"Firstname\";s:8:\"lastname\";s:7:\"Lasname\";s:5:\"email\";s:22:\"someEmail@dotemail.com\";s:12:\"customerType\";i:0;s:11:\"billingInfo\";a:0:{}s:5:\"Mobil\";N;}}" ["stagingId"]=> string(0) "" ["requestId"]=> string(41) "calendarista_req_1557484124_5cd5525ca8249" ["projectList"]=> string(1) "4" ["calendarista_cart"]=> string(0) "" ["controller"]=> string(21) "calendarista_checkout" ["paymentsMode"]=> string(2) "-1" ["originalCost"]=> string(1) "0" ["totalAmountBeforeDiscount"]=> string(1) "0" ["booknow"]=> string(0) "" }


I expect something like this "__viewstats" => (phonenumber data)

  • 写回答

1条回答 默认 最新

  • doulu5109 2019-05-10 12:44
    关注

    I think some of the s:digit entries contain invalid numbers for the first string to unserialize for:

    • 10 for +46736506234
    • 10 for Firstname Lastname
    • 5 for Firstname
    • 4 for Lastname
    • 13 for info@Firstname.se

    I think you would have to find the error in there. If those values we correct and for the example with the whole array you could use:

    $e = "a:4:{i:0;a:1:{s:9:\"projectId\";i:4;}i:1;a:15:{s:14:\"availabilityId\";i:6;s:13:\"availableDate\";s:10:\"2019-05-29\";s:7:\"endDate\";s:10:\"2019-05-29\";s:9:\"startTime\";s:4:\"2569\";s:7:\"endTime\";N;s:13:\"startTimeslot\";s:8:\"10:30 am\";s:11:\"endTimeslot\";s:0:\"\";s:5:\"seats\";i:4;s:12:\"seatsMinimum\";i:1;s:12:\"seatsMaximum\";i:10;s:13:\"dynamicFields\";a:0:{}s:8:\"timezone\";s:16:\"Europe/Stockholm\";s:15:\"_availabilityId\";N;s:14:\"_availableDate\";N;s:8:\"_endDate\";N;}i:6;a:1:{s:9:\"requestId\";s:41:\"calendarista_req_1557482130_5cd54a92b61bd\";}i:4;a:9:{s:12:\"formelements\";a:1:{i:0;a:5:{s:9:\"projectId\";i:4;s:9:\"elementId\";i:6;s:10:\"orderIndex\";i:6;s:5:\"value\";s:12:\"+46736506234\";s:5:\"label\";s:11:\"Phonenumber\";}}s:6:\"userId\";i:0;s:4:\"name\";s:18:\"Firstname Lastname\";s:9:\"firstname\";s:9:\"Firstname\";s:8:\"lastname\";s:8:\"Lastname\";s:5:\"email\";s:17:\"info@Firstname.se\";s:12:\"customerType\";i:0;s:11:\"billingInfo\";a:0:{}s:5:\"Mobil\";N;}}";
    $res = unserialize($e);
    echo $res[4]["formelements"][0]["value"]; // +46736506234
    

    Php demo

    评论

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号