Facebook json消息的编码/解码问题.C#解析 [英] Encoding/decoding issue with Facebook json messages. C# parsing

查看:44
本文介绍了Facebook json消息的编码/解码问题.C#解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将我的会话存档下载为json.我坚持使用奇数编码.

I've download json with my conversations archive. I stuck with odd encoding.

json的示例

{
  "sender_name": "Micha\u00c5\u0082",
  "timestamp": 1411741499,
  "content": "b\u00c4\u0099d\u00c4\u0099",
  "type": "Generic"
},

应该是这样的:

{
  "sender_name": "Michał",
  "timestamp": 1411741499,
  "content": "będę",
  "type": "Generic"
},

我正在尝试像这样反序列化:

I'm trying to deserialize it like this:

var result = File.ReadAllText(jsonPath, encodingIn);
JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
var conversation = serializer.Deserialize<Conversation>(System.Net.WebUtility.HtmlDecode(result));

不幸的是,输出是这样的:

Unfortunately the output is like this:

{
  "sender_name": "MichaÅ\u0082",
  "timestamp": 1411741499,
  "content": "bÄ\u0099dÄ\u0099",
  "type": "Generic"
},

有人知道Facebook如何编码json吗?我尝试了几种方法,但没有结果.

Anyone know how Facebook encoding the json? I've tried several methods but without results.

感谢您的帮助.

推荐答案

以下是答案:

private string DecodeString(string text)
{
    Encoding targetEncoding = Encoding.GetEncoding("ISO-8859-1");
    var unescapeText = System.Text.RegularExpressions.Regex.Unescape(text);
    return Encoding.UTF8.GetString(targetEncoding.GetBytes(unescapeText));
}

我已经收集了所有答案,将它们混合在一起,我们就在这里.谢谢.

I've collect all answers, mixed them and here we are. Thank you.

这篇关于Facebook json消息的编码/解码问题.C#解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆