2016-03-24 19 views
0

多次元配列を持つ.txtファイルを取り込み、ajaxを介して読み込み、データを並べ替えて自分のサイトに吐き出すようにしています。データは平文として戻ってくるだけで、JSON.parse()を使用しても何も戻ってこない。JSON形式の配列とフォーマットのjQuery load txtファイル

私は、ファイルにアクセスするには、これを使用しています:

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

    json = JSON.parse(json); 
}); 

のようにファイルが見えます:問題は、ファイルが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' => ''  
    )) 
); 
+1

ファイルに無効なJSONが含まれています。 jsonが有効でない場合、パーサーはnullを返します。 – Nergal

答えて

0

。カスタムパーサーを作成するか、ファイルを有効なJSONに変換する必要があります。問題は配列とオブジェクトのために '配列'が使用されていることです。構造体を完全に操作する必要があります。また

は、JSONは(ほとんど)もののため、二重引用符を必要とし、=>のすべてのインスタンスは...

TL :に変更する必要があり、DRは、あなたがこれで終わる必要があり、それ容易ではないだろう。 { "Advertising/Media": { "no_hover": 0, "organization": "Marina Reef", .... }, "Construction/Engineering/Real Estate": { "no_hover": 0, "organization": "Al Reyami", "existing_url": "http://www.alphasoftware.com/al-reyami-case-study.asp", .... } }

:また

[{ "industry": "Advertising/Media", "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" }, { "industry": "Construction/Engineering/Real Estate", "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": null }] 、あなたはそうのように、それぞれ同じエントリの「キー」と「業界」の値を使用する場合がありますいずれの方法でも動作しますが、後でJSONオブジェクトにアクセスする方法によって異なります。

関連する問題