【发布时间】:2015-09-19 14:57:05
【问题描述】:
我在数组到 json 的转换中遇到问题,我有一个数组,我想将此数组转换为 json 对象,下面给出了所需的输出,所以请任何人帮助我。
php 数组
Array
(
[0] => Array
(
[application_id] => 132
[application_status] => SUBMITTED
[reference_number] =>
[salutation] =>
[first_name] =>
[middle_name] =>
[last_name] =>
[mother_name] =>
)
[1] => Array
(
[application_id] => 148
[application_status] => SUBMITTED
[reference_number] =>
[salutation] =>
[first_name] =>
[middle_name] =>
[last_name] =>
[mother_name] =>
)
[2] => Array
(
[application_id] => 154
[application_status] => SUBMITTED
[reference_number] =>
[salutation] =>
[first_name] =>
[middle_name] =>
[last_name] =>
[mother_name] =>
)
[3] => Array
(
[application_id] => 182
[application_status] => SUBMITTED
[reference_number] =>
[salutation] =>
[first_name] =>
[middle_name] =>
[last_name] =>
[mother_name] =>
)
[4] => Array
(
[application_id] => 186
[application_status] => SUBMITTED
[reference_number] =>
[salutation] =>
[first_name] =>
[middle_name] =>
[last_name] =>
[mother_name] =>
)
)
像这样将上面的数组转换为 json 对象:
[
{
"application_id": "1",
"application_status": "0",
"reference_number": "/index",
"salutation": "index",
"first_name": "Index",
"middle_name": "Home",
"last_name": "1",
},
{
"application_id": "1",
"application_status": "0",
"reference_number": "/index",
"salutation": "index",
"first_name": "Index",
"middle_name": "Home",
"last_name": "1",
},
{
"application_id": "1",
"application_status": "0",
"reference_number": "/index",
"salutation": "index",
"first_name": "Index",
"middle_name": "Home",
"last_name": "1",
},
{
"application_id": "1",
"application_status": "0",
"reference_number": "/index",
"salutation": "index",
"first_name": "Index",
"middle_name": "Home",
"last_name": "1",
},
{
"application_id": "1",
"application_status": "0",
"reference_number": "/index",
"salutation": "index",
"first_name": "Index",
"middle_name": "Home",
"last_name": "1",
},
]
【问题讨论】:
-
你真的想在一个不知从何而来的 JSON 对象中有一些重复!还是只是一个错字!!
-
不不,它只是一个拼写错误,每个键都有不同的值。 @someOne
标签: php arrays json multidimensional-array