【发布时间】:2018-12-21 15:15:48
【问题描述】:
我有一个将 CSV 转换为 JSON 的 PHP 文件,但我希望输出 JSON 具有与我现在得到的不同的“层次结构”(见下文)。
我的 CSV 文件看起来像这样:
Icon Name, Responses, Performance
03_v10_Assembly_point, 225, 38
55_v10_Fire, 203, 87
23_v10_Warning_volcano, 324, 79
我希望输出的 JSON 看起来像这样:
{
"03_v10_Assembly_point" {
"Responses": "225",
"Performance": "38"
},
"55_v10_Fire" {
"Responses": "203",
"Performance": "87"
},
"23_v10_Warning_volcano" {
"Responses": "324",
"Performance": "79"
}
}
或类似的,重要的是将第一列作为其他参数的“标题”。
有没有办法做到这一点? :(
2018 年 12 月 22 日更新
虽然问题已经得到解答,但这是我得到的原始 JSON 输出:
[
{
"Icon": "03_v10_Assembly_point",
"Responses": "225",
"Performance": "38",
"id": 0
},
{
"Icon": "55_v10_Fire",
"Responses": "203",
"Performance": "87",
"id": 1
},
{
"Icon": "23_v10_Warning_volcano",
"Responses": "324",
"Performance": "79",
"id": 2
}
]
【问题讨论】:
-
是的,有办法做到这一点。你有什么尝试?请发布您的代码。
-
您还应该在问题本身中包含您当前遇到的问题,而不是作为场外链接。当该链接发生变化时,这个问题对未来的访问者来说意义不大。