[英]Auto Convert Json String to C# Object
I have this string below with '\\t', '\\r' and '\\n' which I need to convert to a valid Json format with a loop so that I can Deserializeto an object without listing the object properties. 我下面有一个带有'\\ t','\\ r'和'\\ n'的字符串,我需要使用循环将其转换为有效的Json格式,这样我才能在不列出对象属性的情况下反序列化为对象。
"Title\\tFirstName\\tLastName\\tAge\\r\\nMr\\tBla bla\\tBla bla\\t25\\r\\nMiss\\tBla bla\\tBla bla\\t35\\r\\n" “标题\\ tFirstName \\ tLastName \\ tAge \\ r \\ nMr \\ tBla bla \\ tBla bla \\ t25 \\ r \\ nMiss \\ tBla bla \\ tBla bla \\ t35 \\ r \\ n”
You can use String.Split method to solve your problem. 您可以使用String.Split方法来解决您的问题。
\\r\\n
- this will give you individual rows with data \\r\\n
这将为您提供包含数据的单独行 \\t
symbol - this will give you array of properties \\t
符号将它们分开-这将为您提供属性数组 new { firstName = arrayData[0], lastName = arrayData[1], ..}
, or you can create a new class with all the required properties new { firstName = arrayData[0], lastName = arrayData[1], ..}
,或者可以创建具有所有必需属性的新类。 Json.NET
library for this purpose: http://www.newtonsoft.com/json Json.NET
为此,我建议使用Json.NET
库: http : //www.newtonsoft.com/json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.