Javascript jQuery加载带有数组的txt文件,格式为JSON

Javascript jQuery加载带有数组的txt文件,格式为JSON,javascript,jquery,arrays,json,Javascript,Jquery,Arrays,Json,我试图获取一个包含多维数组的.txt文件,并通过ajax加载它,对数据进行排序,然后在我的站点上输出。但是,数据只是以明文形式返回,即使我对其使用JSON.parse()时,也不会返回任何内容 我正在使用此文件访问该文件: $.get("json/json_data.txt", function(json) { json = JSON.parse(json); }); 该文件看起来像: array(array('industry' => 'Advertising/Media',

我试图获取一个包含多维数组的.txt文件,并通过ajax加载它,对数据进行排序,然后在我的站点上输出。但是,数据只是以明文形式返回,即使我对其使用JSON.parse()时,也不会返回任何内容

我正在使用此文件访问该文件:

$.get("json/json_data.txt", function(json) {

    json = JSON.parse(json);
});
该文件看起来像:

array(array('industry' => 'Advertising/Media',array( 
        'no_hover' => 0,
        'organization' => 'Marina Reef',
        'existing_url => 'http://www.alphasoftware.com/marina-reef-case-study.asp',
        'heading' => '<h3>Giant Touch Screen App</h3>',
        'description'  => 'Interactive brochure application running on a 46\" touch screen.',
        'logo' =>'marina-reef-sized.pmg',
        'large_image'  => 'marina-reef-large.jpg',
        'page_name'  => 'marina'        
    )),
      array('industry' => 'Construction/Engineering/Real Estate',array( 
        'no_hover' => 0,
        'organization' => 'Al Reyami',
        'existing_url => 'http://www.alphasoftware.com/al-reyami-case-study.asp',
        'heading' => '<h3>Enterprise-wide System for Invoicing, Financial Management, Inventory, Human Resources, and More</h3>',
        'description'  => 'Global construction firm uses Alpha Anywhere as its enterprise development and deployment platform, because it required less code than other tools.',
        'logo' =>'al-reyami-sized.png',
        'large_image'  => 'al-reyami-large.jpg',
        'page_name'  => ''      
    ))
);
array(数组(“行业”=>“广告/媒体”,数组(
“无悬停”=>0,
“组织机构”=>“滨海礁”,
'现有url=>'http://www.alphasoftware.com/marina-reef-case-study.asp',
“标题”=>“巨型触摸屏应用程序”,
“说明”=>“在46”触摸屏上运行的交互式手册应用程序。”,
“徽标”=>“marina-reef-Size.pmg”,
“大型图片”=>“marina reef large.jpg”,
“页面名称”=>“玛丽娜”
)),
数组('industry'=>'Construction/Engineering/Real Estate',数组(
“无悬停”=>0,
“组织”=>“Al Reyami”,
'现有url=>'http://www.alphasoftware.com/al-reyami-case-study.asp',
“标题”=>“企业范围的发票、财务管理、库存、人力资源等系统”,
“description”=>“全球建筑公司使用Alpha Anywhere作为其企业开发和部署平台,因为它比其他工具需要更少的代码。”,
“logo”=>“al-reyami-size.png”,
'large_image'=>'al-reyami large.jpg',
“页面名称”=>“
))
);

问题在于文件不是JSON。您必须编写自定义解析器,或将文件转换为有效的JSON。问题在于“数组”用于数组和对象;您必须完全操纵结构

此外,(大多数)JSON需要双引号,所有
=>
的实例都需要更改为

TL;DR你需要以这个结束,这并不容易:


[{
“行业”:“广告/媒体”,
“无悬停”:0,
“组织”:“玛丽娜礁”,
“现有url”:http://www.alphasoftware.com/marina-reef-case-study.asp",
“标题”:“巨型触摸屏应用程序”,
“说明”:“在46”触摸屏上运行的交互式手册应用程序。”,
“徽标”:“marina reef Size.pmg”,
“大型图片”:“marina reef large.jpg”,
“页码名称”:“码头”
}, {
“行业”:“建筑/工程/房地产”,
“无悬停”:0,
“组织”:“Al-Reyami”,
“现有url”:http://www.alphasoftware.com/al-reyami-case-study.asp",
“标题”:“企业范围的发票、财务管理、库存、人力资源等系统”,
“描述”:“全球建筑公司使用Alpha Anywhere作为其企业开发和部署平台,因为它比其他工具需要更少的代码。”,
“徽标”:“al reyami Size.png”,
“大型图片”:“al-reyami large.jpg”,
“页面名称”:空
}]
或者,您可能希望使用“行业”值作为每个相同条目的“键”,如下所示:

{
“广告/媒体”:{
“无悬停”:0,
“组织”:“玛丽娜礁”,
....
},
“建筑/工程/房地产”:{
“无悬停”:0,
“组织”:“Al-Reyami”,
“现有url”:http://www.alphasoftware.com/al-reyami-case-study.asp",
....
}
}


这两种方法都可以,但这取决于您以后打算如何访问JSON对象。

您的文件包含无效的JSON。如果json无效,解析器将返回null。