2013-02-16 64 views
0

我有串像下面(2號線是一個字符串變量),我如何分成2串並在C#中使用JsonConvert類反序列化如何反序列化Json多個結果?

{"operation":"waiting","wait":12121212} 
{"operation":"result","firstname":"bill", "lastname":"last"} 

回答

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 
}