NewLifeX / X

Core basic components: log (file / network), configuration (XML / JSON / HTTP), cache (memory / redis), network (TCP / UDP / HTTP), RPC framework, serialization (binary / XML / JSON), APM performance tracking. 核心基础组件,日志(文件/网络)、配置(XML/Json/Http)、缓存(内存/Redis)、网络(Tcp/Udp/Http)、RPC框架、序列化(Binary/XML/Json)、APM性能追踪。
https://newlifex.com
MIT License
1.76k stars 524 forks source link

对于JValue对象的ToJson()方法,会报错 #127

Closed kimdiego2098 closed 7 months ago

kimdiego2098 commented 1 year ago

【日志级别】:Warning 【日志类名】:上传设备:RabbitMQ上传设备 【日志时间】:2023-07-14 09:40:14:9631989 +08 【日志内容】: RabbitMQClient IP:localhost Port:5672 【异常信息】:System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Cannot access child value on Newtonsoft.Json.Linq.JValue. at Newtonsoft.Json.Linq.JToken.get_First() --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index) at NewLife.Serialization.JsonWriter.WriteObject(Object obj) at NewLife.Serialization.JsonWriter.WriteValue(Object obj) at NewLife.Serialization.JsonWriter.WriteMember(String name, Object value, String comment, Boolean& first) at NewLife.Serialization.JsonWriter.WriteObject(Object obj) at NewLife.Serialization.JsonWriter.WriteValue(Object obj) at NewLife.Serialization.JsonWriter.WriteArray(IEnumerable arr) at NewLife.Serialization.JsonWriter.WriteValue(Object obj) at NewLife.Serialization.JsonWriter.ToJson(Object obj, Boolean indented, Boolean nullValue, Boolean camelCase) at NewLife.Serialization.JsonHelper.ToJson(Object value, Boolean indented)

nnhy commented 1 year ago

Json序列化位于NewLife.Core基础核心库中,需要支持很多项目,无法支持独立组件Newtonsoft.Json的类型。 建议你在发布消息之前,自己做序列化,然后把json发布到队列中。

nnhy commented 7 months ago

核心库ToJson使用自己的Json序列化,可以使用以下代码更换为系统System.Text.Json。 JsonHelper.Default = new SystemJson();