这种数据类型是什么,如何调用数据单独显示

What is this kind of data type and how can i call the data to display it individually

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

这是我收到的数据

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]"}

即JSON。使用 json_decode() https://www.php.net/manual/en/function.json-decode.php or an online json decoder: http://freeonlinetools24.com/json-decode.

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

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