gpt4 book ai didi

c# - 牛顿软件.Json.JsonReaderException : Additional text encountered after finished reading JSON content:

转载 作者:太空狗 更新时间:2023-10-29 21:56:54 26 4
gpt4 key购买 nike

我在从服务器接收时遇到 JSON 数组中的一个奇怪问题,我试图反序列化它但它说

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

类(class)如下。

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

}

Exception: Newtonsoft.Json.JsonReaderException: Additional text encountered after finished reading JSON content: y. Path '', line 1, position 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) at 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) at Listener.Program.LogStatus(Boolean receiving, Byte[] buffer, Int32 length) in at Listener.Program.d__5.MoveNext() in --- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Listener.Program.d__1.MoveNext()

我得到的数组在下面,

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

{"messagetype":"chatmsg","msgid":"6478316959_121","from":"sam","message":"this is msg"} ood morning !"}
{"messagetype":"ping"}g","msgid":"6478316959_121","from":"sam","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);

这将截断其余字符。

关于c# - 牛顿软件.Json.JsonReaderException : Additional text encountered after finished reading JSON content:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35533166/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com