2011-04-23 83 views
1

我有此JSON編碼值我該如何解析這個json數據?

"AllEvents":[ 
     { 
      "eventId":"22", 
      "eventTitle":"VANGUARD Friday w/ Colette - Free All Night w/ RSVP!", 
      "eventImageUrl":"events/64ffcc09e1c3e73a17c998035ecd7f72.jpeg", 
      "eventDescription":"Pete G presents  Friday, September 24, 2010 @ VANGUARD Hollywood OM Records & Candy Talk welcomes .. Main Room: .COLETTE (Los Angeles) OM Records, Candy Talk .CHUCK LOVE (Minneapolis) Love Network Tour, Om Records .ANDY COMPTON (UK) The Rurals, Kholofelo Lp Tour Patio Hosted by Droid Behavior: .RAíZ aka ACID CIRCUS (Los Angeles) Droid Behavior .DEAN PAUL vs VIK CARRILLO (Los Angeles) Droid Behavior .DJ MODESTY (Los Angeles) Friendly Integration 21+ to Enter | Doors Open 10pm-3am+ Free Entry All Night Long w/ RSVP __________________________________ + PLAYHOUSE Mondays | ECCO Wednesdays | MY HOUSE Fridays | VANGUARD Fridays | MUSIC BOX Saturdays + __________________________________ To RSVP Please 1.) E-Mail [email protected] 2.) Text 323.394.3917 (Pete G) 3.) Sign Up Online @ http://www.SuperstarsVIP.com" 
     },{ 
      "eventId":"30", 
      "eventTitle":"test title", 
      "eventImageUrl":"events/eb5afdce0e8e687b21112162733df5ba.jpeg", 
      "eventDescription":"zxzxzx" 
     },{ 
      "eventId":"80", 
      "eventTitle":"OH YOU FANCY FRIDAYS @ Push Lounge", 
      "eventImageUrl":"events/6eda786bdd8d07d93e300305df66cac4.jpeg", 
      "eventDescription":"Skum Entertainment presents...<br /> 
OH YOU FANCY FRIDAYS<br /> 
Every other Friday "Oh You Fancy! Friday's" at Push Loungee<br /> 
...2 for 1 drinks from 9pm-12am!<br /> 
$5 cover - Admission includes a drink ticket!<br /> 
21+ only - Bring your ID!<br /> 
<br /> 

This week! Friday, February 11th<br /> 
- DJ G-Rock spinning your favorites in Hip Hop, Top 40 & Rap<br /> 
- Live performance by T-KO (www.myspace.com/terrakilla)<br /> 
- Roaming photography by OHDAGYO & SKUM<br /> 
- Wings World Food Truck out front!<br /> 
- Special birthday celebration for your favorite bartender Jesse Diaz!<br /> 
<br /> 
PUSH LOUNGE<br /> 

20969 Ventura Blvd<br /> 
Woodland Hills, CA 91364<br /> 
(Entrance is on Peralta St)<br /> 
Parking is FREE!" 
     },{ 
      "eventId":"21", 
      "eventTitle":"Benny Benassi - Limited $25 Tickets!", 
      "eventImageUrl":"events/2f64e7a15388364d0a9059f42725df77.jpeg", 
      "eventDescription":"Decor presents BENNY BENASSI this Saturday @ The Music Box 10pm-4am!<br /> 
<br /> 
Insomniac and The Box will collaborate to bring the electronic music scene to vivid life Saturday nights at the legendary Music Box Theatre. <br /> 
<br /> 
Experience our mega sound system, world class artists, sexy dancefloor, CO2 cannons, Rooftop patio, gigantic LED visual display at Hollywood's biggest 21+ party!<br /> 
<br /> 
"Benny Benassi (born Marco Benassi; July 13, 1967) is a Grammy Award winning Italian DJ and producer of electro house music. He is best known for his 2002 summer club hit "Satisfaction". Benny Benassi ranks as the 10th most popular DJ in the world according to The DJ List website. On October 28, 2009, DJ Magazine announced the results of their annual Top 100 DJ Poll, with Ultra Records artist Benny Benassi placed #26, 13 spots higher than the previous year."<br /> 

<br /> 
http://en.wikipedia.org/wiki/Benny_Benassi<br /> 
<br /> 
Pre-Sales Highly Encouraged!! Get them NOW before ticket prices increase. If you don't have a pre-sale ticket you will probably not get in. This event is likely to sell out in advance. If it doesn't tickets at the door are going to cost an arm and a leg and you're going to have to either wait in line for hours or arrive by 9pm. Please be forewarned! ;)<br /> 
<br /> 
$25 tickets online for a limited time @<br /> 
http://tinyurl.com/benny-benassi-at-the-box" 
     } 

,但是當我在http://jsonformatter.curiousconcept.com/#jsonformatter運行它,它給了錯誤

我有這樣的應用變量,給我描述。

$AllEvent[$i]['even_desc'] = str_replace(array("\r\n", "\r", "\n","<br />"), " ", $AllEvent[$i]['even_desc']); 

請大家幫忙。

+0

請發佈您遇到的錯誤 – Mat 2011-04-23 06:51:34

+0

這不是有效的JSON。如果是,字符串內部的'''將被轉義 – alex 2011-04-23 06:53:36

+0

還缺少結尾]和周圍的{} – joelpittet 2011-04-23 06:55:26

回答

1

看看我answer to this question

你也需要在JSON逃脫"(如果你看一下語法你的問題的代碼高亮你會看到藍色的某些部分,這哪裏是"的轉義錯過:

Every other Friday "Oh You Fancy! Friday's" at Push Loungee<br /> 

應該變成:

Every other Friday \"Oh You Fancy! Friday's\" at Push Loungee<br /> 

注意\"而不是"

+0

在此處獲取錯誤無效字符字符串「Skum Entertainment禮物... < br/> OH YOU FANCY星期日< br/> 星期五" Oh You Fancy!星期五的" at Push Loungee < br/> ... 2從9 pm-12am 2飲料! < br/> $ 5封面 - 入場券包括一張飲料券! < br/> 僅限21+ - 帶上您的ID! < br/> < br/> 這周!週五2月11日< BR/> - DJ G-石紡您的收藏夾嘻哈,前40 &說唱< BR/> - 通過T-KO(www.myspace現場表演。com/terrakilla)< br/> - 漫遊電話「 – Exception 2011-04-23 07:05:34

1

你有雙引號 結帳一個雙引號Every other Friday "Oh You Fancy! Friday's" at Push Loungee

3

你不能解析它。它是無效構建的。您的選擇是要麼手動修復它,要麼使用一種解決方法。

,而不是分析你可以使用一個近似的提取,不關心報價的正確性:

preg_match_all('#"(\w+)":"(.*?)"(?:,|\s*\})#ims', 
     $broken_json_input, $data, PREG_SET_ORDER); 
print_r($data); 

這會給你鑰匙=>值標記的列表。但他們沒有分組。所以你必須手動迭代該列表並獲取你想要的內容。

+0

+1第三種選擇是從源頭請求適當的JSON,無論是誰,無論它在哪裏 – 2011-04-23 07:38:51

+1

確實。但它可能是模板打印輸出,就像RSS返回它的全盛時期,所以憤怒的信件可能不會工作,沒有理由不發送他們:} – mario 2011-04-23 07:42:20