2017-05-22 7 views
0

私はPHPインポータプロジェクトで作業しています.jsonファイルを読み込んで解析し、それを(配列として)反復する必要がありますが、 phpadminでインポートされたjsonファイルでそれを行う方法を理解できません。JSONを使用してPHPの配列に変換する際の問題

これは私が試した結果であり、有効な配列ではありません。

$filedata = file_get_contents($mi_file_type); 
    $objson = json_decode($filedata); 
    foreach($objson AS $prop => $val) { 
    echo '<br/>'. $prop .' - '. $val; 
} 

と...

$json = json_encode($json_data); 
$json2 = explode('[',$json); 
$json3 = explode(']',$json2[1]); 
$json = $json3[0]; 
$json_array = json_decode($json); 

そのコードのどれもここでPHPの配列

を作成しなかったJSON(どのように私は配列にこれを変換することができますか?)

"\/**\n Export to JSON plugin for PHPMyAdmin\n @version 4.6.6\n *\/\n\n\/\/ Database 'drto7192_directory'\n\n\/\/ drto7192_directory.data_posts\n\n[{"post_id":"1","post_title":"member_search","post_caption":"","post_content":"<a class='suggest-link' href='{{link}}' data-state='{{link}}' data-heading='{{comes_f}}'> <div class='left-suggest-col' data-photo='{{photo}}'> <img src='{{photo}}' data-state='{{photo}}'> <\\\/div> <div class='right-suggest-col' data-photo='{{photo}}'> <p class='media-heading' data-state='{{value}}' data-heading='{{comes_f}}'>{{value}}<\\\/p> <p class='suggest-origin' data-state='{{comes_f}}'>{{comes_f}}<\\\/p> <p class='location' data-state='{{location}}'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-08-12 13:34:49","post_job":""}, {"post_id":"2","post_title":"classifieds_search","post_caption":"","post_content":"<a class='suggest-link' href='{{link}}' data-state='{{link}}' data-heading='{{comes_f}}'> <div class='left-suggest-col' data-photo='{{photo}}'> <img src='{{photo}}' data-state='{{photo}}'> <\\\/div> <div class='right-suggest-col' data-photo='{{photo}}'> <p class='media-heading' data-state='{{value}}' data-heading='{{comes_f}}'>{{value}}<\\\/p> <p class='suggest-origin' data-state='{{comes_f}}'>{{comes_f}}<\\\/p> <p class='location' data-state='{{location}}'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:30:33","post_job":""}, {"post_id":"3","post_title":"coupons_search","post_caption":"","post_content":"<a class='suggest-link' href='{{link}}' data-state='{{link}}' data-heading='{{comes_f}}'> <div class='left-suggest-col' data-photo='{{photo}}'> <img src='{{photo}}' data-state='{{photo}}'> <\\\/div> <div class='right-suggest-col' data-photo='{{photo}}'> <p class='media-heading' data-state='{{value}}' data-heading='{{comes_f}}'>{{value}}<\\\/p> <p class='suggest-origin' data-state='{{comes_f}}'>{{comes_f}}<\\\/p> <p class='location' data-state='{{location}}'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:30:58","post_job":""}, {"post_id":"4","post_title":"events_search","post_caption":"","post_content":"<a class='suggest-link' href='{{link}}' data-state='{{link}}' data-heading='{{comes_f}}'> <div class='left-suggest-col' data-photo='{{photo}}'> <img src='{{photo}}' data-state='{{photo}}'> <\\\/div> <div class='right-suggest-col' data-photo='{{photo}}'> <p class='media-heading' data-state='{{value}}' data-heading='{{comes_f}}'>{{value}}<\\\/p> <p class='suggest-origin' data-state='{{comes_f}}'>{{comes_f}}<\\\/p> <p class='location' data-state='{{location}}'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:31:29","post_job":""}, {"post_id":"5","post_title":"jobs_search","post_caption":"","post_content":"<a class='suggest-link' href='{{link}}' data-state='{{link}}' data-heading='{{comes_f}}'> <div class='left-suggest-col' data-photo='{{photo}}'> <img src='{{photo}}' data-state='{{photo}}'> <\\\/div> <div class='right-suggest-col' data-photo='{{photo}}'> <p class='media-heading' data-state='{{value}}' data-heading='{{comes_f}}'>{{value}}<\\\/p> <p class='suggest-origin' data-state='{{comes_f}}'>{{comes_f}}<\\\/p> <p class='location' data-state='{{location}}'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:32:00","post_job":""}, {"post_id":"6","post_title":"products_search","post_caption":"","post_content":"<a class='suggest-link' href='{{link}}' data-state='{{link}}' data-heading='{{comes_f}}'> <div class='left-suggest-col' data-photo='{{photo}}'> <img src='{{photo}}' data-state='{{photo}}'> <\\\/div> <div class='right-suggest-col' data-photo='{{photo}}'> <p class='media-heading' data-state='{{value}}' data-heading='{{comes_f}}'>{{value}}<\\\/p> <p class='suggest-origin' data-state='{{comes_f}}'>{{comes_f}}<\\\/p> <p class='location' data-state='{{location}}'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:32:38","post_job":""}, {"post_id":"7","post_title":"property_search","post_caption":"","post_content":"<a class='suggest-link' href='{{link}}' data-state='{{link}}' data-heading='{{comes_f}}'> <div class='left-suggest-col' data-photo='{{photo}}'> <img src='{{photo}}' data-state='{{photo}}'> <\\\/div> <div class='right-suggest-col' data-photo='{{photo}}'> <p class='media-heading' data-state='{{value}}' data-heading='{{comes_f}}'>{{value}}<\\\/p> <p class='suggest-origin' data-state='{{comes_f}}'>{{comes_f}}<\\\/p> <p class='location' data-state='{{location}}'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:32:57","post_job":""}, {"post_id":"8","post_title":"videos_search","post_caption":"","post_content":"<a class='suggest-link' href='{{link}}' data-state='{{link}}' data-heading='{{comes_f}}'> <div class='left-suggest-col' data-photo='{{photo}}'> <img src='{{photo}}' data-state='{{photo}}'> <\\\/div> <div class='right-suggest-col' data-photo='{{photo}}'> <p class='media-heading' data-state='{{value}}' data-heading='{{comes_f}}'>{{value}}<\\\/p> <p class='suggest-origin' data-state='{{comes_f}}'>{{comes_f}}<\\\/p> <p class='location' data-state='{{location}}'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:33:24","post_job":""}, {"post_id":"12","post_title":"audio_search","post_caption":"","post_content":"<a class='suggest-link' href='{{link}}' data-state='{{link}}' data-heading='{{comes_f}}'> <div class='left-suggest-col' data-photo='{{photo}}'> <img src='{{photo}}' data-state='{{photo}}'> <\\\/div> <div class='right-suggest-col' data-photo='{{photo}}'> <p class='media-heading' data-state='{{value}}' data-heading='{{comes_f}}'>{{value}}<\\\/p> <p class='suggest-origin' data-state='{{comes_f}}'>{{comes_f}}<\\\/p> <p class='location' data-state='{{location}}'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2016-04-19 13:16:02","post_job":""}, {"post_id":"13","post_title":"articles_search","post_caption":"","post_content":"<a class='suggest-link' href='{{link}}' data-state='{{link}}' data-heading='{{comes_f}}'> <div class='left-suggest-col' data-photo='{{photo}}'> <img src='{{photo}}' data-state='{{photo}}'> <\\\/div> <div class='right-suggest-col' data-photo='{{photo}}'> <p class='media-heading' data-state='{{value}}' data-heading='{{comes_f}}'>{{value}}<\\\/p> <p class='suggest-origin' data-state='{{comes_f}}'>{{comes_f}}<\\\/p> <p class='location' data-state='{{location}}'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2016-04-19 13:21:57","post_job":""}, {"post_id":"14","post_title":"blogs_search","post_caption":"","post_content":"<a class='suggest-link' href='{{link}}' data-state='{{link}}' data-heading='{{comes_f}}'> <div class='left-suggest-col' data-photo='{{photo}}'> <img src='{{photo}}' data-state='{{photo}}'> <\\\/div> <div class='right-suggest-col' data-photo='{{photo}}'> <p class='media-heading' data-state='{{value}}' data-heading='{{comes_f}}'>{{value}}<\\\/p> <p class='suggest-origin' data-state='{{comes_f}}'>{{comes_f}}<\\\/p> <p class='location' data-state='{{location}}'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2016-04-19 13:22:39","post_job":""}, {"post_id":"15","post_title":"photos_search","post_caption":"","post_content":"<a class='suggest-link' href='{{link}}' data-state='{{link}}' data-heading='{{comes_f}}'> <div class='left-suggest-col' data-photo='{{photo}}'> <img src='{{photo}}' data-state='{{photo}}'> <\\\/div> <div class='right-suggest-col' data-photo='{{photo}}'> <p class='media-heading' data-state='{{value}}' data-heading='{{comes_f}}'>{{value}}<\\\/p> <p class='suggest-origin' data-state='{{comes_f}}'>{{comes_f}}<\\\/p> <p class='location' data-state='{{location}}'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2016-04-19 13:22:58","post_job":""}, {"post_id":"16","post_title":"CBRE 2016 market report","post_caption":"","post_content":"<p>In terms of real estate, leasing activities continue to gain momentum. Rent growth and occupancy levels witnessed sustained improvements across all property types. Nevertheless, the industry still needs more transparent approvals and a regulatory body to safeguard the interest of foreign investors. Developers should understand the objectives and investment pattern of these investors in order to spur more foreign capital.<\\\/p>","post_category":"Category 1","post_org_url":"","post_filename":"blog\\\/cbre-2016-market-report-16","post_image":"","post_type":"Account","data_type":"20","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"vietnam, real estate, home, land, property, properties, 2016, market, asia,","post_status":"0","post_live_date":"20160910204236","post_author":"Tu Cuong Nguyen","post_token":"2263571392563eaec0819c325c2b2377","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"19","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"20160910202900","data_id":"14","lat":"10.7936808","lon":"106.71132639999996","revision_timestamp":"2016-09-10 08:42:36","post_job":""}, {"post_id":"17","post_title":"Testing video","post_caption":"","post_content":"<p>Test<\\\/p>","post_category":"","post_org_url":"","post_filename":"videos\\\/testing-video-17","post_image":"","post_type":"Account","data_type":"9","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"Video 1","post_status":"1","post_live_date":"20161112181728","post_author":"Kim Nguyen","post_token":"3135fde90d71949c645b1296d0394f31","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"21","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"13","lat":"10.786462","lon":"106.69798289999994","revision_timestamp":"2016-11-12 05:17:28","post_job":""}, {"post_id":"18","post_title":"360 Demo","post_caption":"","post_content":"<p>This is a 360 Demo Video<\\\/p>","post_category":"","post_org_url":"","post_filename":"videos\\\/360-demo-18","post_image":"","post_type":"Account","data_type":"9","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"1","post_live_date":"20161213230604","post_author":"Kim Nguyen","post_token":"e2ebaf841f0621c4cb2ef6ad28eccc9c","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"21","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"13","lat":"10.786462","lon":"106.69798289999994","revision_timestamp":"2016-12-13 10:06:04","post_job":""}]\n" 
です
+0

有効なJSONを返すようにコードを修正してください – Satya

+0

phpmyadminによってjsonファイルが生成されています – ricardorios

+0

有効にするにはどうすれば変更できますか? @サティヤ – ricardorios

答えて

1

jsonはコメントのために解析しません。 var_dump($objson);を実行すると、値がNULLであることがわかります。コメントを取り除くことで、jsonは解析することができます。

+0

ポスターのリクエストにより追加されました。 mickmackusaによるより完全な答え –

0

$objson = json_decode($filedata);から$objson = json_decode($filedata, true);に変更してください。 2番目のパラメータをtruejson_decode()として渡すと、オブジェクトではなく連想配列が返されます。

1

あなたは単に開始と終了から非JSONをトリミングする必要があります...

入力:

$json='"\/**\n Export to JSON plugin for PHPMyAdmin\n @version 4.6.6\n *\/\n\n\/\/ Database \'drto7192_directory\'\n\n\/\/ drto7192_directory.data_posts\n\n[{"post_id":"1","post_title":"member_search","post_caption":"","post_content":"<a class=\'suggest-link\' href=\'{{link}}\' data-state=\'{{link}}\' data-heading=\'{{comes_f}}\'> <div class=\'left-suggest-col\' data-photo=\'{{photo}}\'> <img src=\'{{photo}}\' data-state=\'{{photo}}\'> <\\\/div> <div class=\'right-suggest-col\' data-photo=\'{{photo}}\'> <p class=\'media-heading\' data-state=\'{{value}}\' data-heading=\'{{comes_f}}\'>{{value}}<\\\/p> <p class=\'suggest-origin\' data-state=\'{{comes_f}}\'>{{comes_f}}<\\\/p> <p class=\'location\' data-state=\'{{location}}\'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-08-12 13:34:49","post_job":""}, {"post_id":"2","post_title":"classifieds_search","post_caption":"","post_content":"<a class=\'suggest-link\' href=\'{{link}}\' data-state=\'{{link}}\' data-heading=\'{{comes_f}}\'> <div class=\'left-suggest-col\' data-photo=\'{{photo}}\'> <img src=\'{{photo}}\' data-state=\'{{photo}}\'> <\\\/div> <div class=\'right-suggest-col\' data-photo=\'{{photo}}\'> <p class=\'media-heading\' data-state=\'{{value}}\' data-heading=\'{{comes_f}}\'>{{value}}<\\\/p> <p class=\'suggest-origin\' data-state=\'{{comes_f}}\'>{{comes_f}}<\\\/p> <p class=\'location\' data-state=\'{{location}}\'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:30:33","post_job":""}, {"post_id":"3","post_title":"coupons_search","post_caption":"","post_content":"<a class=\'suggest-link\' href=\'{{link}}\' data-state=\'{{link}}\' data-heading=\'{{comes_f}}\'> <div class=\'left-suggest-col\' data-photo=\'{{photo}}\'> <img src=\'{{photo}}\' data-state=\'{{photo}}\'> <\\\/div> <div class=\'right-suggest-col\' data-photo=\'{{photo}}\'> <p class=\'media-heading\' data-state=\'{{value}}\' data-heading=\'{{comes_f}}\'>{{value}}<\\\/p> <p class=\'suggest-origin\' data-state=\'{{comes_f}}\'>{{comes_f}}<\\\/p> <p class=\'location\' data-state=\'{{location}}\'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:30:58","post_job":""}, {"post_id":"4","post_title":"events_search","post_caption":"","post_content":"<a class=\'suggest-link\' href=\'{{link}}\' data-state=\'{{link}}\' data-heading=\'{{comes_f}}\'> <div class=\'left-suggest-col\' data-photo=\'{{photo}}\'> <img src=\'{{photo}}\' data-state=\'{{photo}}\'> <\\\/div> <div class=\'right-suggest-col\' data-photo=\'{{photo}}\'> <p class=\'media-heading\' data-state=\'{{value}}\' data-heading=\'{{comes_f}}\'>{{value}}<\\\/p> <p class=\'suggest-origin\' data-state=\'{{comes_f}}\'>{{comes_f}}<\\\/p> <p class=\'location\' data-state=\'{{location}}\'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:31:29","post_job":""}, {"post_id":"5","post_title":"jobs_search","post_caption":"","post_content":"<a class=\'suggest-link\' href=\'{{link}}\' data-state=\'{{link}}\' data-heading=\'{{comes_f}}\'> <div class=\'left-suggest-col\' data-photo=\'{{photo}}\'> <img src=\'{{photo}}\' data-state=\'{{photo}}\'> <\\\/div> <div class=\'right-suggest-col\' data-photo=\'{{photo}}\'> <p class=\'media-heading\' data-state=\'{{value}}\' data-heading=\'{{comes_f}}\'>{{value}}<\\\/p> <p class=\'suggest-origin\' data-state=\'{{comes_f}}\'>{{comes_f}}<\\\/p> <p class=\'location\' data-state=\'{{location}}\'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:32:00","post_job":""}, {"post_id":"6","post_title":"products_search","post_caption":"","post_content":"<a class=\'suggest-link\' href=\'{{link}}\' data-state=\'{{link}}\' data-heading=\'{{comes_f}}\'> <div class=\'left-suggest-col\' data-photo=\'{{photo}}\'> <img src=\'{{photo}}\' data-state=\'{{photo}}\'> <\\\/div> <div class=\'right-suggest-col\' data-photo=\'{{photo}}\'> <p class=\'media-heading\' data-state=\'{{value}}\' data-heading=\'{{comes_f}}\'>{{value}}<\\\/p> <p class=\'suggest-origin\' data-state=\'{{comes_f}}\'>{{comes_f}}<\\\/p> <p class=\'location\' data-state=\'{{location}}\'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:32:38","post_job":""}, {"post_id":"7","post_title":"property_search","post_caption":"","post_content":"<a class=\'suggest-link\' href=\'{{link}}\' data-state=\'{{link}}\' data-heading=\'{{comes_f}}\'> <div class=\'left-suggest-col\' data-photo=\'{{photo}}\'> <img src=\'{{photo}}\' data-state=\'{{photo}}\'> <\\\/div> <div class=\'right-suggest-col\' data-photo=\'{{photo}}\'> <p class=\'media-heading\' data-state=\'{{value}}\' data-heading=\'{{comes_f}}\'>{{value}}<\\\/p> <p class=\'suggest-origin\' data-state=\'{{comes_f}}\'>{{comes_f}}<\\\/p> <p class=\'location\' data-state=\'{{location}}\'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:32:57","post_job":""}, {"post_id":"8","post_title":"videos_search","post_caption":"","post_content":"<a class=\'suggest-link\' href=\'{{link}}\' data-state=\'{{link}}\' data-heading=\'{{comes_f}}\'> <div class=\'left-suggest-col\' data-photo=\'{{photo}}\'> <img src=\'{{photo}}\' data-state=\'{{photo}}\'> <\\\/div> <div class=\'right-suggest-col\' data-photo=\'{{photo}}\'> <p class=\'media-heading\' data-state=\'{{value}}\' data-heading=\'{{comes_f}}\'>{{value}}<\\\/p> <p class=\'suggest-origin\' data-state=\'{{comes_f}}\'>{{comes_f}}<\\\/p> <p class=\'location\' data-state=\'{{location}}\'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2015-10-13 14:33:24","post_job":""}, {"post_id":"12","post_title":"audio_search","post_caption":"","post_content":"<a class=\'suggest-link\' href=\'{{link}}\' data-state=\'{{link}}\' data-heading=\'{{comes_f}}\'> <div class=\'left-suggest-col\' data-photo=\'{{photo}}\'> <img src=\'{{photo}}\' data-state=\'{{photo}}\'> <\\\/div> <div class=\'right-suggest-col\' data-photo=\'{{photo}}\'> <p class=\'media-heading\' data-state=\'{{value}}\' data-heading=\'{{comes_f}}\'>{{value}}<\\\/p> <p class=\'suggest-origin\' data-state=\'{{comes_f}}\'>{{comes_f}}<\\\/p> <p class=\'location\' data-state=\'{{location}}\'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2016-04-19 13:16:02","post_job":""}, {"post_id":"13","post_title":"articles_search","post_caption":"","post_content":"<a class=\'suggest-link\' href=\'{{link}}\' data-state=\'{{link}}\' data-heading=\'{{comes_f}}\'> <div class=\'left-suggest-col\' data-photo=\'{{photo}}\'> <img src=\'{{photo}}\' data-state=\'{{photo}}\'> <\\\/div> <div class=\'right-suggest-col\' data-photo=\'{{photo}}\'> <p class=\'media-heading\' data-state=\'{{value}}\' data-heading=\'{{comes_f}}\'>{{value}}<\\\/p> <p class=\'suggest-origin\' data-state=\'{{comes_f}}\'>{{comes_f}}<\\\/p> <p class=\'location\' data-state=\'{{location}}\'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2016-04-19 13:21:57","post_job":""}, {"post_id":"14","post_title":"blogs_search","post_caption":"","post_content":"<a class=\'suggest-link\' href=\'{{link}}\' data-state=\'{{link}}\' data-heading=\'{{comes_f}}\'> <div class=\'left-suggest-col\' data-photo=\'{{photo}}\'> <img src=\'{{photo}}\' data-state=\'{{photo}}\'> <\\\/div> <div class=\'right-suggest-col\' data-photo=\'{{photo}}\'> <p class=\'media-heading\' data-state=\'{{value}}\' data-heading=\'{{comes_f}}\'>{{value}}<\\\/p> <p class=\'suggest-origin\' data-state=\'{{comes_f}}\'>{{comes_f}}<\\\/p> <p class=\'location\' data-state=\'{{location}}\'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2016-04-19 13:22:39","post_job":""}, {"post_id":"15","post_title":"photos_search","post_caption":"","post_content":"<a class=\'suggest-link\' href=\'{{link}}\' data-state=\'{{link}}\' data-heading=\'{{comes_f}}\'> <div class=\'left-suggest-col\' data-photo=\'{{photo}}\'> <img src=\'{{photo}}\' data-state=\'{{photo}}\'> <\\\/div> <div class=\'right-suggest-col\' data-photo=\'{{photo}}\'> <p class=\'media-heading\' data-state=\'{{value}}\' data-heading=\'{{comes_f}}\'>{{value}}<\\\/p> <p class=\'suggest-origin\' data-state=\'{{comes_f}}\'>{{comes_f}}<\\\/p> <p class=\'location\' data-state=\'{{location}}\'>{{location}}<\\\/p> <\\\/div> <\\\/a> ","post_category":"","post_org_url":"","post_filename":"","post_image":"","post_type":"","data_type":"98","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"0","post_live_date":"","post_author":"","post_token":"","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"0","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"0","lat":"","lon":"","revision_timestamp":"2016-04-19 13:22:58","post_job":""}, {"post_id":"16","post_title":"CBRE 2016 market report","post_caption":"","post_content":"<p>In terms of real estate, leasing activities continue to gain momentum. Rent growth and occupancy levels witnessed sustained improvements across all property types. Nevertheless, the industry still needs more transparent approvals and a regulatory body to safeguard the interest of foreign investors. Developers should understand the objectives and investment pattern of these investors in order to spur more foreign capital.<\\\/p>","post_category":"Category 1","post_org_url":"","post_filename":"blog\\\/cbre-2016-market-report-16","post_image":"","post_type":"Account","data_type":"20","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"vietnam, real estate, home, land, property, properties, 2016, market, asia,","post_status":"0","post_live_date":"20160910204236","post_author":"Tu Cuong Nguyen","post_token":"2263571392563eaec0819c325c2b2377","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"19","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"20160910202900","data_id":"14","lat":"10.7936808","lon":"106.71132639999996","revision_timestamp":"2016-09-10 08:42:36","post_job":""}, {"post_id":"17","post_title":"Testing video","post_caption":"","post_content":"<p>Test<\\\/p>","post_category":"","post_org_url":"","post_filename":"videos\\\/testing-video-17","post_image":"","post_type":"Account","data_type":"9","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"Video 1","post_status":"1","post_live_date":"20161112181728","post_author":"Kim Nguyen","post_token":"3135fde90d71949c645b1296d0394f31","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"21","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"13","lat":"10.786462","lon":"106.69798289999994","revision_timestamp":"2016-11-12 05:17:28","post_job":""}, {"post_id":"18","post_title":"360 Demo","post_caption":"","post_content":"<p>This is a 360 Demo Video<\\\/p>","post_category":"","post_org_url":"","post_filename":"videos\\\/360-demo-18","post_image":"","post_type":"Account","data_type":"9","post_clicks":"0","post_price":"0.00","feed_id":"0","blog_id":"0","post_date":"","post_tags":"","post_status":"1","post_live_date":"20161213230604","post_author":"Kim Nguyen","post_token":"e2ebaf841f0621c4cb2ef6ad28eccc9c","post_updated":"","post_featured":"0","post_image_saved":"0","twitter_post":"0","user_id":"21","service_id":"0","additional_fields":"","post_expire_date":"","post_start_date":"","data_id":"13","lat":"10.786462","lon":"106.69798289999994","revision_timestamp":"2016-12-13 10:06:04","post_job":""}]\n"'; 

方法:

$ JSON = '[' SUBSTR。 ($ json、strpos($ json、 '[')+ 1); // json以外の先をトリミングする $ json = substr($ json、0、strrpos($ json、 '\ n'))); //非JSON

$json=preg_match('/\[.*\]/',$json,$out)?$out[0]:null; 
var_export(json_decode($json,true)); 

出力は(あまりが合理的に表示するために)ここでdemo linkだ末尾のトリム。

関連する問題