我需要解析一个看起来像 JSON 文件但它不是的文件。它错过了:
字符,所以我无法使用json_decode
. 我不是这个文件的所有者,所以我必须照原样对待它。我怎样才能解析这个文件?有什么想法吗?谢谢
"sound_materials"
{
"common"
{
"value" "0"
"start_drag_sound" "ui.inv_pickup"
"end_drag_sound" "ui.inv_drop"
"equip_sound" "ui.inv_equip"
}
"chest"
{
"value" "1"
"start_drag_sound" "ui.inv_pickup_chest"
"end_drag_sound" "ui.inv_drop_chest"
}
"pennant"
{
"value" "2"
"start_drag_sound" "ui.inv_pickup_pennant"
"end_drag_sound" "ui.inv_drop_pennant"
}
"key"
{
"value" "3"
"start_drag_sound" "ui.inv_pickup_key"
"end_drag_sound" "ui.inv_drop_key"
}
"metal_small"
{
"value" "4"
"start_drag_sound" "ui.inv_pickup_metalsmall"
"end_drag_sound" "ui.inv_drop_metalsmall"
"equip_sound" "ui.inv_equip_metalsmall"
}
"metal_armor"
{
"value" "5"
"start_drag_sound" "ui.inv_pickup_metalarmour"
"end_drag_sound" "ui.inv_drop_metalarmour"
"equip_sound" "ui.inv_equip_metalarmour"
}
"metal_blade"
{
"value" "6"
"start_drag_sound" "ui.inv_pickup_metalblade"
"end_drag_sound" "ui.inv_drop_metalblade"
"equip_sound" "ui.inv_equip_metalblade"
}
"metal_heavy"
{
"value" "7"
"start_drag_sound" "ui.inv_pickup_metalheavy"
"end_drag_sound" "ui.inv_drop_metalheavy"
"equip_sound" "ui.inv_equip_metalheavy"
}
"staff_or_blunt"
{
"value" "8"
"start_drag_sound" "ui.inv_pickup_staff"
"end_drag_sound" "ui.inv_drop_staff"
"equip_sound" "ui.inv_equip_staff"
}
"robes"
{
"value" "9"
"start_drag_sound" "ui.inv_pickup_robes"
"end_drag_sound" "ui.inv_drop_robes"
"equip_sound" "ui.inv_equip_robes"
}
"leather"
{
"value" "10"
"start_drag_sound" "ui.inv_pickup_leather"
"end_drag_sound" "ui.inv_drop_leather"
"equip_sound" "ui.inv_equip_leather"
}
"quiver"
{
"value" "11"
"start_drag_sound" "ui.inv_pickup_quiver"
"end_drag_sound" "ui.inv_drop_quiver"
"equip_sound" "ui.inv_equip_quiver"
}
"stone"
{
"value" "12"
"start_drag_sound" "ui.inv_pickup_stone"
"end_drag_sound" "ui.inv_drop_stone"
"equip_sound" "ui.inv_equip_stone"
}
"wood"
{
"value" "13"
"start_drag_sound" "ui.inv_pickup_wood"
"end_drag_sound" "ui.inv_drop_wood"
"equip_sound" "ui.inv_equip_wood"
}
"bone"
{
"value" "14"
"start_drag_sound" "ui.inv_pickup_bone"
"end_drag_sound" "ui.inv_drop_bone"
"equip_sound" "ui.inv_equip_bone"
}
"jug"
{
"value" "15"
"start_drag_sound" "ui.inv_pickup_jug"
"end_drag_sound" "ui.inv_drop_jug"
"equip_sound" "ui.inv_equip_jug"
}
"gun"
{
"value" "16"
"start_drag_sound" "ui.inv_pickup_gun"
"end_drag_sound" "ui.inv_drop_gun"
"equip_sound" "ui.inv_equip_gun"
}
"highvalue"
{
"value" "17"
"start_drag_sound" "ui.inv_pickup_highvalue"
"end_drag_sound" "ui.inv_drop_highvalue"
"equip_sound" "ui.inv_equip_highvalue"
}
}
编辑:
所以我使用了 h2o 建议的正则表达式,它可以很好地格式化文件。我的错误是在上面的例子中我只放了一个带有 1 个线路键的部分。
我在文件的其他部分中有子键,在这种情况下,我需要为子键添加 [ ] 分隔符..: