2015-01-05 35 views
0

我試圖把html內容放入json中,它壞了。無效的JSON把HTML放在

我無效的Json http://i.imgur.com/8wfEikY.png

{ 
    "item": { 
     "title": "Japanese investors back Lookup, a messaging app for local shopping in India", 
     "desc": "An infusion of US$116,000 from Japan's social games company DeNA and Teruhide Sato, founder of BEENOS, takes the three-month-old startup\u2019s seed funding to US$382,000.", 
     "link": "https:\/\/www.techinasia.com\/dena-teruhide-sato-beenos-fund-lookup\/", 
     "content": "<p><img src="https: \/\/www-techinasia.netdna-ssl.com\/wp-content\/uploads\/2015\/01\/lookup-app-main-720x289.jpg" alt="lookupappmain" width="720" height="289" class="aligncentersize-largewp-image-213938" \/><\/p>\n<p>Bangalore-based instant messaging app <a href="https: \/\/www.techinasia.com\/tag\/lookup\/">Lookup<\/a> – a Craiglist cum WhatsApp for local businesses – just got its third dose of seed funding. Japan&#8217;s leading social games company <a href="https: \/\/www.techinasia.com\/tag\/dena\/">DeNA<\/a> and Teruhide Sato, founder of BEENOS group, a global conglomerate with ecommerce holdings and a business incubator, invested US$116,000 into this three-month-old startup founded by Deepak Ravindran, a young serial entrepreneur.<\/p>\n<p>「Both our recent investors have strong footholds in the mobile space and have successfully led innovations in Japan,」 says Ravindran, suggesting that the investors would be giving Lookup more than just funding.<\/p>\n<p><a href="http: \/\/www.lookup.to">Lookup<\/a> lists businesses, restaurants, and even police stations for users to connect with. Unlike Craigslist or JustDial which would give you a number to dial, Lookup lets you shoot off a message to the local businesses without leaving the app. You can find prices and availability of products or services at local businesses, book appointments at salons, or make reservations at restaurants with this app. Any store or restaurant using Lookup can then respond instantly.<\/p>\n<p>Lookup has a call center tracking the messages to ensure that its users receive responses immediately, even if a store is not using the app. 「Our guarantee is that you get answers within five minutes. We do this by employing dedicated people for handling your request. Lookup’s call center fields your responses, calls up stores, and types answers back to you in real-time. No calling, no waiting,」 Ravindran told <em>Tech in Asia<\/em>.<\/p>\n<p>To celebrate the latest funding from Japanese investors, Lookup is gifting free sushi for a week to new users from Bangalore who download the app. For this, it has tied up with two Japanese restaurants Shiro and Ginseng.<\/p>\n<p>With this latest infusion, Lookup’s seed round of venture capital funding closed at US$382,000. It had earlier bagged US$166,000 from tech billionaire Kris Gopalakrishnan, co-founder of Indian IT bellwether Infosys, and US$100,000 from MKS Switzerland SA, a precious metals and financial services group of companies.<\/p>\n<p><center><strong>See: <a href="https: \/\/www.techinasia.com\/college-dropout-turned-mit-top-innovator-rolls-craigslist-whatsapp-app-local-shopping-india\/">College dropout turned MIT top innovator rolls Craigslist and WhatsApp into one app for local shopping in India<\/a><\/strong><\/center><\/p>\n<p>This post <a href="https: \/\/www.techinasia.com\/dena-teruhide-sato-beenos-fund-lookup\/" title="JapaneseinvestorsbackLookup, 
     amessagingappforlocalshoppinginIndia">Japanese investors back Lookup, a messaging app for local shopping in India<\/a> appeared first on Tech in Asia.<\/p>" 
    } 
} 

我在PHP做什麼

$arr = array(); 
$arr["item"]["content"] = $content; // $content is dynamic, scrapped from somewhere 
echo json_encode($arr, true); 

我試圖ヶ輛和addcslashes($ item_content,「'),但nnoe這項工作的。

+0

請從上你的圖像添加文本的問題,而不是一個外部鏈接。 – Magnilex

+0

@Magnilex我做了部分收錄 –

回答

1

這是因爲「登錄圖片標籤。您可以使用HTML實體功能在解碼功能中對其進行編碼以對其進行解碼。

更簡單的方法是將圖片網址保存在您的商品的其他屬性中。

+0

快速鏈接:http://php.net/htmlentities – BLewis

+0

我不能,我必須得到整個內容。 –

+0

如果您希望快速完成此操作,您應該使用\ –

1

您的內容中沒有使用引號(「」),這意味着您的內容字符串僅爲"<p><img src=",然後PHP對這些東西的剩餘內容感到困惑。

你需要改變它是這樣的:

"content": "<p><img src=\"https: \/\/www-techinasia.netdna-ssl.com\/wp-content\/uploads\/2015\/01\/lookup-app-main-720x289.jpg" alt=\"loo...More content..." 

(我不結束的字符串引號前添加\ - 在未來 - 查找語法高亮 - 如果事情改變顏色沒有你期待一個變量的末尾 - 然後出了問題)

如果你想用PHP來做到這一點 - 你可以使用HTML實體功能(http://php.net/htmlentities)或乾脆和addslashes功能(http://php.net/manual/en/function.addslashes.php

E.g.

<?php $str = "A 'quote' is <b>bold</b>"; 

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt; echo 
htmlentities($str); 

// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt; echo 
htmlentities($str, ENT_QUOTES); ?>` 

[引用:PHP手冊]

<?php $str = "Is your name O'Reilly?"; 

// Outputs: Is your name O\'Reilly? 
echo addslashes($str); ?> 

[引用:PHP手冊]

+0

來避免引用我嘗試了addcslashes($ content,''')但不起作用。 –

+0

您可以發佈輸出嗎? – BLewis