我需要解析看起來像JSON文件的文件,但它不是。它錯過了:
char,因此我無法使用json_decode
解析它。我不是這個文件的所有者,所以我必須像它一樣。我如何解析這個文件?有什麼想法嗎?謝謝PHP如何使用不合適的json格式解析文件
"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 suggered正則表達式,它的偉大工程,以格式化文件。我的錯誤是,在上面的例子中,我只把一個部分用1行鍵。
我有一些人,你有子鍵,在這種情況下,我應該需要添加[]分隔符的子項文件的一部分..:
以及它不是json ...它是在一個數組?或一個字符串?或笏? –
你必須做一些重字符串解析。見http://stackoverflow.com/questions/13236819/how-to-fix-badly-formatted-json-in-php – subZero
如何正則表達式?您可以執行搜索並替換爲帶有引號內的兩個字符串的行,用空格分隔,並用冒號替換空格。 –