【问题标题】:What is this kind of data type and how can i call the data to display it individually [duplicate]这种数据类型是什么以及如何调用数据以单独显示它[重复]
【发布时间】:2019-09-24 01:56:39
【问题描述】:

所以我是 php 的新手,我想问一下这是什么数据类型?它是搅拌还是字符串数组?我怎么能让他们说我是否只想在字符串中使用名称变量。我怎么称呼他们?如果它在 jsonresponse 我该怎么做呢?如果可能的话,我想在显示时使用 mustache 模板。基本上我想单独显示字符串中的每个数据。

这是我收到的数据

string(1247) "[
{
"name": "POSLAJU NEXT DAY",
"service_code": "POSMY-PN-SDP",
"company_code": "POSMY",
"description": "Booking before 11.30am. \\nPickup and delivery in 1-2 days by PosLaju. \\nAvailable on working days days only. \\nNo booking in advance later than tomorrow. \\nYou can also book online and drop your document/parcel at the nearest POSLAJU branch. \\nOnly available on the web. \\nYou have to print the Consignment Note and follow our Packaging Guidelines.",
"instruction": "Please print the Consignment Note and follow our Packaging Guidelines.",
"payment_methods": [],
"cod_rate": 0,
"price": 6
 },
 {
  "name": "SAME DAY - MORNING",
  "service_code": "MDMY-SDD-S-MORNING-KV",
  "company_code": "MDMY",
  "description": "Booking before 8am. \\nPickup before 10am. \\nDelivery 
    before 2pm. \\nBy motorbike. \\nAvailable on working days only. 
   \\nPayment by credit/cash by sender/cash by receiver.",
  "instruction": "Please label your package with our Consignment Note or 
    Tracking No and follow our Packaging Guidelines.",
    "payment_methods": [
    {
      "code": "CASHPICKUP",
      "name": "Cash By Sender",
     "price": "3"
   }
 ],
   "cod_rate": 0.03,
  "price": 15
 }
 ]"

这是jsonresponse中的代码

   {"response":"[\n  {\n    \"name\": \"POSLAJU NEXT DAY\",\n    \"service_code\": \"POSMY-PN-SDP\",\n    \"company_code\": \"POSMY\",\n    \"description\": \"Booking before 11.30am. \\\\nPickup and delivery in 1-2 days by PosLaju. \\\\nAvailable on working days days only. \\\\nNo booking in advance later than tomorrow. \\\\nYou can also book online and drop your document\/parcel at the nearest POSLAJU branch. \\\\nOnly available on the web. \\\\nYou have to print the Consignment Note and follow our Packaging Guidelines.\",\n    \"instruction\": \"Please print the Consignment Note and follow our Packaging Guidelines.\",\n    \"payment_methods\": [],\n    \"cod_rate\": 0,\n    \"price\": 6\n  },\n  {\n    \"name\": \"SAME DAY - MORNING\",\n    \"service_code\": \"MDMY-SDD-S-MORNING-KV\",\n    \"company_code\": \"MDMY\",\n    \"description\": \"Booking before 8am. \\\\nPickup before 10am. \\\\nDelivery before 2pm. \\\\nBy motorbike. \\\\nAvailable on working days only. \\\\nPayment by credit\/cash by sender\/cash by receiver.\",\n    \"instruction\": \"Please label your package with our Consignment Note or Tracking No and follow our Packaging Guidelines.\",\n    \"payment_methods\": [\n      {\n        \"code\": \"CASHPICKUP\",\n        \"name\": \"Cash By Sender\",\n        \"price\": \"3\"\n      }\n    ],\n    \"cod_rate\": 0.03,\n    \"price\": 15\n  }\n]"}

【问题讨论】:

标签: php string jsonresponse mustache.php


【解决方案1】:

它称为 JSON(代表 JavaScript Object Notation),这是一种用于在 PHP 和 JavaScript(或任何其他支持语言)之间共享数据的格式。

要在 PHP 中使用 JSON 数据,您必须将获得的字符串传递给 json_decode。这将返回解码的数据,在您的情况下这将是一个数组。然后,您可以像使用普通数组一样访问数据。只需对解码后的字符串做一个 var_dump,你就会看到它包含的数据。

【讨论】:

  • 好的,我知道如何将它发送到 javascript 文件?我需要做一个 jsonresponse 来发送它们吗?
  • 每次 AJAX 调用(从 JS 发送)在 PHP 和 JavaScript 之间交换数据,然后从 PHP 返回 json。
【解决方案2】:

那是 JSON。使用json_decode()https://www.php.net/manual/en/function.json-decode.php或在线json解码器:http://freeonlinetools24.com/json-decode

【讨论】:

    猜你喜欢
    • 2019-10-11
    • 2019-07-28
    • 1970-01-01
    • 2011-09-08
    • 1970-01-01
    • 1970-01-01
    • 2012-08-27
    • 2018-01-30
    • 1970-01-01
    相关资源
    最近更新 更多