来自Twitter API的JSON包含\ u2019 [英] JSON from twitter API contains \u2019
问题描述
这是我通过twitter API获得的JSON文件的一部分:
This is part of my JSON file I obtain through the twitter API:
文字":科学家发现了研究分子的新方法:女王的研究人员已经发现了研究分子的方法... http://bit.ly/chbweE "
我在项目中使用PHP.
I am using PHP for my project.
使用json_decode函数后,\ u2019转换为’,这基本上是很烦人的.
After using the json_decode function, \u2019 is converted into ’, which basically is really annoying.
我尝试使用$raw_json = preg_replace("u2019","'",$raw_json)
,但是json_decode
函数返回NULL.
I tried using $raw_json = preg_replace("u2019","'",$raw_json)
, but then the json_decode
function returns NULL.
还有其他方法可以将\ u2019转换为'吗?
Is there any other way I can convert the \u2019 into ' ?
谢谢
这是我获取JSON的方式:
This is how I am obtaining the JSON:
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "http://search.twitter.com/search.json?q=from%3Agizmodo&rpp=10");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$raw_json = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
推荐答案
这可能与您在输出中使用的字符集有关.如果要输出到HTML页面,请尝试将以下meta标签添加到您的头部:
This is probably a problem with the charset you're using in your output. If you're outputing to an HTML page, try adding the following meta tag to your head section:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
这篇关于来自Twitter API的JSON包含\ u2019的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!