我在 javascript 文件中有一些 JSON 数据
数据是使用 javascript 对象文字表示法构建的;
var CMS = window.CMS = window.CMS || {};
CMS.Data = window.CMS.Data = window.CMS.Data || {};
CMS.Data['LANGUAGES'] = [
{id:"chi", value:"Chinese"},
{id:"spa", value:"Spanish"},
{id:'eng', value:"English"},
{id:"hin", value:"Hindi"},
];
CMS.Data['AGE_RANGE'] = [{id:'18', value:"18"}, {id:'25', value:"25"}, {id:'30', value:"30"}, {id:'35', value:"35"}, {id:'40', value:"40"}, {id:'50', value:"50"}, {id:'60', value:"60"}, {id:'70', value:"70"}, {id:'80', value:"80"}, {id:'90', value:"90"}, {id:'100', value:"100"}];
CMS.Data['HEIGHT_RANGE'] = [{id:'140-150', value:"140-150"}, {id:'150-160', value:"150-160"}, {id:'160-170', value:"160-170"}, {id:'180-190', value:"180-190"}];
完整数据可在https://gist.github.com/mithunqb/675613fe985fe2afbbcf获得
我需要让它在 PHP 数组中可用。
我不能简单地加载内容并应用json_decode
$json_string = file_get_contents('data.json');
$json_array = json_decode($json_string, true);
由于json文件里面的内容实际上不是一个有效的JSON字符串,所以上面的操作会返回NULL;
我怎样才能做到这一点?