0
我有串像下面(2號線是一個字符串變量),我如何分成2串並在C#中使用JsonConvert類反序列化如何反序列化Json多個結果?
{"operation":"waiting","wait":12121212}
{"operation":"result","firstname":"bill", "lastname":"last"}
我有串像下面(2號線是一個字符串變量),我如何分成2串並在C#中使用JsonConvert類反序列化如何反序列化Json多個結果?
{"operation":"waiting","wait":12121212}
{"operation":"result","firstname":"bill", "lastname":"last"}
您可以將字符串分割成使用字符串數組新行分隔符,然後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
}