【发布时间】:2016-09-18 06:04:16
【问题描述】:
我正在尝试从我的服务器传递数据并将其显示在 UWP Windows 应用中。数据存储在 mySQL 数据库中
这是通过 PHP 输出到此处的网页 http://www.rwscripts.com/scorealerts/v3/request.php?action=getTeams 使用此代码
// Serialize the data structure
$result = json_encode($data,JSON_PRETTY_PRINT);
// Display the XML document
header('Content-type: application/json; charset=utf-8');
print $result;
然后我在我的应用程序中使用 HttpWebRequest 阅读此内容,然后使用 JSON.net 反序列化 JSON
JArray obj = JsonConvert.DeserializeObject(str.Trim()) as JArray;
if (obj == null || obj.Count == 0) return;
foreach (NotificationTeam nt in from JObject team in obj
select
new NotificationTeam
{
Title = team.Value<string>("teamName"),
TeamID = team.Value<int>("tid"),
Followers = team.Value<int>("followers")
})
{
nt.Notifications = ScoreManager.GetMgr().GetTeamNotification(nt.TeamID);
notificationTeams.Add(nt);
}
在我的应用中显示时的输出是这样的
需要更改流程的哪一部分才能正确显示 unicode 字符?
【问题讨论】:
-
你试过
Encoding.ASCII.GetString(yourBytes) -
你建议我在哪里使用它?我的网络响应以字符串形式返回
StreamReader requestReader = new StreamReader(response.GetResponseStream()); String webResponse = requestReader.ReadToEnd(); -
你能把你的实际 Unicode 字符用文本而不是图片发布吗?
-
在数据库中是 1.FC Köln C# 输出是“1.FC Köln”,json 输出可以在上面的链接中看到
-
在插入Mysql之前需要用SET NAMES utf8更改服务器连接