[英]How do I Deserialize Json multiple results?
I have string like below (2 lines are in one string variable), How do I divide into 2 strings and deserialize using JsonConvert class in C# 我有下面的字符串(2行在一个字符串变量中),如何在C#中使用JsonConvert类分成2个字符串并反序列化
{"operation":"waiting","wait":12121212}
{"operation":"result","firstname":"bill", "lastname":"last"}
You could split the string into an array of strings using the new line separator and then JSON deserialize each line. 您可以使用新行分隔符将字符串拆分为字符串数组,然后JSON反序列化每一行。 To split a string you could use the Split
method. 要拆分字符串,可以使用Split
方法。
For example: 例如:
string input = "... your input string ...";
string[] lines = input.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
foreach (string line in lines)
{
// you could use a JSON serializer here to deserialize the line
// and possibly add it to some result collection
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.