我有一个包含以下数据的json文件。它被http://jsonlint.com/检测为无效的json,因此在php中被检测为字符串而不是json。有关如何在PHP中解决此问题的任何建议?我无法手动更改每个文件,因为我有超过一千个文件。
{"contributors":null,"text":"@bru: i'll NEVER stop rollerblading! had a great dream last night that i was rollerblading while wearing a jetpack. must investigate...","geo":null,"retweeted":false,"in_reply_to_screen_name":null,"truncated":false,"entities":{"urls":[],"hashtags":[],"user_mentions":[{"id":null,"name":null,"indices":[0,4],"screen_name":"@bru","id_str":null}]},"in_reply_to_status_id_str":null,"id":1856693,"in_reply_to_user_id_str":null,"source":"web","favorited":false,"in_reply_to_status_id":null,"retweet_count":0,"in_reply_to_user_id":null,"created_at":"Sat Dec 30 12:47:22 +0000 2006","id_str":"1856693","place":null,"user":{"location":"Cambridge, UK","default_profile":false,"statuses_count":0,"profile_background_tile":true,"lang":"","profile_link_color":"78B0C8","id":12763,"following":false,"favourites_count":0,"protected":false,"profile_text_color":"000000","contributors_enabled":false,"description":"an infinitely hot and dense dot","verified":false,"name":"Rik Abel","profile_sidebar_border_color":"CDCDCD","profile_background_color":"FFFFFF","created_at":"Mon Jan 16 21:30:35 +0000 2006","default_profile_image":false,"followers_count":0,"geo_enabled":true,"profile_background_image_url":"http://a1.twimg.com/images/themes/theme/bg.gif","follow_request_sent":false,"url":"http://www.rikabel.com","utc_offset":0,"time_zone":"London","notifications":null,"profile_use_background_image":true,"friends_count":0,"profile_sidebar_fill_color":"ffffff","screen_name":"rikabel","id_str":"12763","profile_image_url":"riksplit.jpg","show_all_inline_media":false,"is_translator":false,"listed_count":0}}
{"info":{"message":"Replay Request Completed","sent":"2013-12-24T03:19:36+00:00","activity_count":1}}
答案 0 :(得分:2)
你有两个对象,主要的json必须是一个对象或一个数组。
Parse error on line 77:
...ed_count": 0 }}{ "info": {
---------------------^
Expecting 'EOF', '}', ',', ']'
我最喜欢这类问题的网站(或只是google验证json在线)
您必须修改php中的字符串才能获得有效的json。 如果您拥有的所有文件都包含多个对象,则可以将列表包装为数组。
$jsonToParse = '['. str_replace('}{', '},{', $jsonStringFromFile) .']';
它不漂亮,但它应该有用。