序列化的JSON不进行序列化

mum43rcc  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(90)

我在JSON对象中嵌入了一些JSON代码,我使用JsonConvert.SerializeObject()为自己正确转义,然后我立即尝试JsonConvert.SerializeObject()并得到一个错误。
第一个月

sortlyObject . notes = JsonConvert . SerializeObject ( @"{ ""ID_3DCS"": """ + id_3dcs + @""", ""Name"": """ + name + @""", ""EXT_ID"": """ + ext_id + @""", ""FreeShippingLevel"": " + freeShippingLevel . ToString ( @"" , "null" ) + @", ""TaxRate"": " + taxRate . ToString ( @"" , "null" ) + @", ""CurrencyRate"": " + currencyRate . ToString ( @"" , "null" ) + @", ""CurrencyCode"": """ + currencyCode . ToUpper ( ) + @""", ""LeadTime"": " + leadTime . ToString ( @"" , "null" ) + @" }" );

Vendor test = JsonConvert.DeserializeObject <Vendor> ( sortlyObject . notes );

字符串
从JsonConvert.SeralizeObject输出的字符串是:

"{ \"ID_3DCS\": \"3F\", \"Name\": \"3Form\", \"EXT_ID\": \"1\", \"FreeShippingLevel\": null, \"TaxRate\": null, \"CurrencyRate\": null, \"CurrencyCode\": \"USD\", \"LeadTime\": null }"


sortlyObject是一个封装JSON的类。
notes是一个我想存储JSON的字符串字段。
我试过使用空值,这也不能解析,所以我为decimal创建了自己的扩展?.ToString()返回null,以及int?.ToString()返回null。
我希望它能正确解析。

xqk2d5yq

xqk2d5yq1#

只需执行JsonConvert.DeserializeObject<Vendor>(jsonString),其中jsonString是

string jsonString = @"{ ""ID_3DCS"": """ + id_3dcs + @""", ""Name"": """ + name + @""", ""EXT_ID"": """ + ext_id + @""", ""FreeShippingLevel"": " + freeShippingLevel . ToString ( @"" , "null" ) + @", ""TaxRate"": " + taxRate . ToString ( @"" , "null" ) + @", ""CurrencyRate"": " + currencyRate . ToString ( @"" , "null" ) + @", ""CurrencyCode"": """ + currencyCode . ToUpper ( ) + @""", ""LeadTime"": " + leadTime . ToString ( @"" , "null" ) + @" }"

字符串
跳过SerializeObject,简单地将jsonString格式化,您应该可以成功地获得Vendor

相关问题