【问题标题】:How to convert json objects into a PHP array [duplicate]如何将json对象转换为PHP数组[重复]
【发布时间】:2014-09-27 02:57:17
【问题描述】:

我希望能够将我的 JSON 对象转换为数组。php 中有一个内置函数可以让我这样做吗?

这是我的 json 对象:

in_userid: "38"
in_email: "user@email.com"
in_firstname: "John"
in_lastname: "Mason"
in_mobilenumber: "00000000000"
in_password: "pass12345"
in_phonenumber: "0000000"

我希望它看起来像这样:

Array(
     in_userid => "38",
     in_email => "user@email.com",
     in_firstname => "John",
     in_lastname => "Mason",
     in_mobilenumber => "00000000000",
     in_password => "pass12345",
     in_phonenumber => "0000000",
);

我该怎么做?

【问题讨论】:

  • json_decode($json, !0);
  • 你不能在谷歌搜索你的标题吗?
  • 在发布问题之前,请尝试至少进行最基本的搜索。这是非常非常基本的(这本身不是问题)并且已经被多次询问和回答(这是一个问题)。

标签: php arrays json


【解决方案1】:

使用json_decode()。它采用 JSON 编码的字符串并将其转换为 PHP 变量。请参阅文档中的 json_decode 函数。

【讨论】:

  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
  • @WebChemist 感谢您的建议,下次一定会记住的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-06
  • 2015-04-21
  • 2015-02-05
  • 2014-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多