2014-01-06 95 views
-2

我有一個包含以下數據的json文件。它在http://jsonlint.com/上被檢測爲無效的json,因此在php中被檢測爲字符串而不是json。有關如何解決這個問題在PHP中的任何建議?我無法手動更改每個文件,因爲我有超過一千個文件。JSON文件無效

{"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

你可以從找出文件中的錯誤開始。 – njzk2

+0

這是一個還是兩個JSON文件? –

回答

2

你有兩個對象,主json必須是一個對象或一個數組本身。

Parse error on line 77: 
...ed_count": 0 }}{ "info": {  
---------------------^ 
Expecting 'EOF', '}', ',', ']' 

我最喜歡的網站這種類型的問題(或只是谷歌的在線驗證JSON)

http://jsonlint.com/

你將不得不修改PHP中的字符串得到有效的JSON。 如果您擁有的所有文件都由多個對象組成,那麼您可以將該列表作爲數組包裝。

$jsonToParse = '['. str_replace('}{', '},{', $jsonStringFromFile) .']'; 

它不漂亮,但它應該工作。