我创建了一个类,并尝试将其反序列化为该对象,但它说
课程如下.
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);
这将截断其余的字符.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。