<!DOCTYPE html>
<html>
<head>
<title>WeekAPI</title>
<meta charset="utf-8">
</head>
<body>
Tag Value from Variable
<h1 id="txtDisplay">Please Wait..</h1>
Tag Value from API
<h1 id="txtResponse">Please Wait..<h1>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
var tag_value = "\uD83D\uDE05\uD83D\uDE00\uD83D\uDE02\uD83D\uDE2C\uD83D\uDE10\uD83D\uDE0E";
$("#txtDisplay").html(tag_value);
var api = "http://week.esy.es/api?id=140393107018&institute=039&branch=07&semester=7&callback=?";
$.getJSON(api, function(data) {
//response tag value is same as tag_value variable
$("#txtResponse").html(data.schedule.friday[0].tag);
});
</script>
</body>
</html>
API响应数据
{
"ok": true,
"message": "Successful.",
"schedule": {
"monday": [
{
"type": "lecture",
"_id": 2,
"start": "11:32 AM",
"end": "11:32 AM",
"teacher": "KPP",
"subject": "Compiler Design",
"tag": ""
}
],
"tuesday": [],
"wednesday": [],
"thursday": [],
"friday": [
{
"type": "holiday",
"_id": 2,
"start": "09:30 AM",
"end": "10:21 AM",
"name": "\\u0928\\u0935\\u0930\\u093E\\u0924\\u094D\\u0930\\u093F",
"tag": "\\uD83D\\uDE05\\uD83D\\uDE00\\uD83D\\uDE02\\uD83D\\uDE2C\\uD83D\\uDE10\\uD83D\\uDE0E"
}
],
"saturday": [],
"sunday": []
}
}
第一种情况
将表情符号的unicode值存储在tag_value
变量中
使用$("#txtDisplay").html(tag_value);
在txtDisplay部分显示。
它正常工作
但是当
第二种情况
从api检索标签值(与上述相同的值)
使用$("#txtResponse").html(data.schedule.friday[0].tag);
在txtResponse部分显示。
它无法显示表情符号。 它显示文本而不是表情符号。
eval
)。最好在源头解决这个问题。 - bobince