我有文本文件中的数据,我加载到数组行明智,但最近我注意到当“μ”进入数据然后json_encode后退空白响应,当我从数据中删除“μ”然后json_encode函数工作< / p>
我有php版本5.5.3
$dat = array("0"=>"hello","1"=>"world");
echo json_encode($dat); // work
$data = array("0"=>"hello","1"=>"180.00 10µH");
echo json_encode($data); // blank response ..
我在github php页面上搜索了json_enocde函数,但它全部都在C中,
所以任何想法如何修补此功能
答案 0 :(得分:2)
使用以下代码:
{
"sports": [
{
"name": "baseball",
"id": 1,
"uid": "s:1",
"leagues": [
{
"name": "Major League Baseball",
"abbreviation": "mlb",
"id": 10,
"uid": "s:1~l:10",
"groupId": 9,
"shortName": "MLB",
"events": [
{
"id": 350506120,
"uid": "s:1~l:10~e:350506120",
"date": "2015-05-06T17:05:00Z",
"season": {
"year": 2015,
"type": 2,
"description": "regular",
"startDate": "2015-04-05T07:00:00Z",
"endDate": "2015-10-05T06:59:59Z"
},
"timeValid": true,
"competitions": [
{
"id": 350506120,
"uid": "s:1~l:10~c:350506120",
"date": "2015-05-06T17:05:00Z",
"timeValid": true,
"competitors": [
{
"type": "team",
"score": 7,
"homeAway": "home",
"isWinner": true,
"team": {
"id": 20,
"uid": "s:1~l:10~t:20",
"location": "Washington",
"name": "Nationals",
"nickname": "Washington",
"abbreviation": "WSH",
"color": "0a295d",
"links": {
"api": {
"teams": {
"href": "http://api-partners.espn.com/v1/sports/baseball/mlb/teams/20"
}
}
},
"record": {
"summary": "14-15",
"wins": 14,
"losses": 15,
"overtimeLosses": 1,
"ties": 0
}
}
},
{
"type": "team",
"score": 5,
"homeAway": "away",
"isWinner": false,
"team": {
"id": 28,
"uid": "s:1~l:10~t:28",
"location": "Miami",
"name": "Marlins",
"nickname": "Miami",
"abbreviation": "MIA",
"color": "0081c7",
"links": {
"api": {
"teams": {
"href": "http://api-partners.espn.com/v1/sports/baseball/mlb/teams/28"
}
}
},
// ....
答案 1 :(得分:0)
试试这个:
$dat = array("0"=>"hello","1"=>"world");
echo json_encode($dat); // work
$data = array("0"=>"hello","1"=>"180.00 10µH");
echo json_encode($data, JSON_UNESCAPED_UNICODE);