我正在使用PHP导入程序项目,我需要加载一个json文件并解析它并迭代它(作为一个数组),但我已经工作了一段时间并且无法弄清楚如何使用phpadmin导入的json文件来做到这一点。
这是我尝试过的,没有结果o无效的数组。
$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 :(得分: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 =&#39; [&#39; .substr($ JSON,strpos($ JSON,&#39; [&#39)+ 1); //修剪领先的非json
$ JSON = SUBSTR($ JSON,0,strrpos($ JSON,&#39; \ n&#39;)); //修剪尾随的非json
$json=preg_match('/\[.*\]/',$json,$out)?$out[0]:null;
var_export(json_decode($json,true));
输出(太多而无法合理显示)这是demo link。
答案 1 :(得分:1)
由于评论,json没有解析。如果你执行var_dump($objson);
,你会发现该值为NULL。删除注释将允许json解析。
答案 2 :(得分:0)
将$objson = json_decode($filedata);
更改为$objson = json_decode($filedata, true);
。通过将第二个参数作为true
json_decode()
传递,将返回关联数组而不是对象。