【发布时间】:2018-08-27 21:35:05
【问题描述】:
好的,我已经进行了一些搜索,但没有找到答案,所以我要试一试。
我有一个可以输出以下信息的 JSON 文件:
[
{
"Contact name(s)": "Person 1, Person 2",
"Contact title(s)": "Head Comacho, Other Guy",
"Contact email(s)": "email1@email.net, email@email.com",
"Contact phone": "123-456-7890, 789-456-1230",
},
{
"Contact name(s)": "Some Dude",
"Contact title(s)": "Cool Title",
"Contact email(s)": "things@email.com",
"Contact phone": "555-555-5555",
},
"Contact name(s)": "",
"Contact title(s)": "",
"Contact email(s)": "",
"Contact phone": "",
}
]
不幸的是,当数据出现时,这就是数据的命名方式。出我的手。无论如何,我必须得到它,以便拥有多个联系人的这些将分组到他们自己的数组中。这是它需要的样子:
Array
(
[0] => Array
(
[contact_name] => Person 1
[contact_title] => Head Comacho
[contact_email] => email1@email.net
[contact_phone] => 123-456-7890
)
[1] => Array
(
[contact_name] => Person 2
[contact_title] => Other Title
[contact_email] => email@email.com
[contact_phone] => 789-456-1230
)
)
Array
(
[0] => Array
(
[contact_name] => Some Dude
[contact_title] => Cool Title
[contact_email] => things@email.com
[contact_phone] => 555-555-5555
)
)
Array
(
[0] => Array
(
[contact_name] =>
[contact_title] =>
[contact_email] =>
[contact_phone] =>
)
)
我能够将数据转换为自己的数组,如下所示:
Array
(
[contact_name] => Array
(
[0] => Person 1
[1] => Person 2
)
[contact_title] => Array
(
[0] => Head Comacho
[1] => Other Guy
)
[contact_email] => Array
(
[0] => email1@email.net
[1] => email@email.com
)
[contact_phone] => Array
(
[0] => 123-456-7890
[1] => 789-456-1230
)
)
Array
(
.....etc
)
我将如何像第一个示例一样获得它?
抱歉,如果之前已经回答过这个问题,我不知道该如何表达我的问题。感谢您提供任何和所有帮助。
【问题讨论】:
-
您是否缺少某些字段?就像现在一样,JSON 无效(最后一个字段上的额外逗号和最后一个对象上缺少左括号)。