我有如下所示的字符串(2行在一个字符串变量中),如何在C#中使用JsonConvert类分成2个字符串并反序列化
{"operation":"waiting","wait":12121212}
{"operation":"result","firstname":"bill", "lastname":"last"}
答案 0 :(得分:2)
您可以使用新行分隔符将字符串拆分为字符串数组,然后JSON反序列化每一行。要拆分字符串,您可以使用Split
方法。
例如:
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
}