加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Newtonsoft.Json.JsonReaderException:读完JSON内容后遇

发布时间:2020-12-15 22:27:46 所属栏目:百科 来源:网络整理
导读:我在 JSON数组中遇到一个奇怪的问题,当从服务器接收时,我试图反序列化它,但它说 我创建了一个类,并尝试将其反序列化为该对象,但它说 课程如下. class bundle{ public string msgid { get; set; } public string messagetype { get; set; } public string mes
我在 JSON数组中遇到一个奇怪的问题,当从服务器接收时,我试图反序列化它,但它说

我创建了一个类,并尝试将其反序列化为该对象,但它说

课程如下.

class bundle
{
    public string msgid { get; set; }
    public string messagetype { get; set; }
    public string message { get; set; }
    public string from { get; set; }

}

例外:Newtonsoft.Json.JsonReaderException:完成读取JSON内容后遇到的其他文本:y.路径”,第1行,第93位.
???at Newtonsoft.Json.JsonTextReader.Read()
???at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader,Type objectType,Boolean checkAdditionalContent)
???at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader,Type objectType)
???在Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader,Type objectType)
???at Newtonsoft.Json.JsonConvert.DeserializeObject(String value,Type type,JsonSerializerSettings settings)
???at Newtonsoft.Json.JsonConvert.DeserializeObject(String value)
???在Listener.Program.LogStatus(布尔接收,Byte []缓冲区,Int32长度)in Listener.Program.d__5.MoveNext()in —从前一个位置抛出异常的堆栈跟踪结束—
???在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
???在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
???在System.Runtime.CompilerServices.TaskAwaiter.GetResult()
???在Listener.Program.d__1.MoveNext()

我得到的数组如下,

{"messagetype":"chatmsg","msgid":"123_119","from":"sam","message":"Hi there,good morning ! "}                                                                                                                            
{"messagetype":"chatmsg","msgid":"123_120","message":"how are you?"}                                                                                                                            

{"messagetype":"chatmsg","msgid":"6478316959_121","message":"this is msg"} ood morning !"}                                                                                                                            
{"messagetype":"ping"}g","message":"you are crazy"} orning ! "}

最后是意外的令牌.

解决方法

经过大量的工作,我想到了这个:

string final = string.Empty;
string name = encoder.GetString(buffer);
char []arr = name.ToArray();

boolean bln = true;
foreach (char item in arr)
{
    if (bln)
    {
        if (item == '}')
        {
            final += item.ToString();
            break;
        }
        else
        {
            final += item.ToString();
        }
    }
}

Console.WriteLine(final);

这将截断其余的字符.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读