string json = "{
"Alias": "[email protected]",
"Name": "qwe",
"Gender": 1,
"SlaveList": "[email protected],[email protected]",
"Position": "xx",
"Tel": "",
"Mobile": "12178879669",
"ExtId": "",
"PartyList": {
"Count": 1,
"List": [{
"Value": ""
}
]
}"
本人要从以上这个字符串中取出"[email protected],[email protected]",求大神帮忙,很急,用c#
------解决思路----------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string json = @"{
""Alias"": ""[email protected]"",
""Name"": ""qwe"",
""Gender"": 1,
""SlaveList"": ""[email protected],[email protected]"",
""Position"": ""xx"",
""Tel"": """",
""Mobile"": ""12178879669"",
""ExtId"": """",
""PartyList"": {
""Count"": 1,
""List"": [{
""Value"": """"
}]
}
}";
var obj = JsonConvert.DeserializeObject<dynamic>(json);
Console.WriteLine(obj.SlaveList);
Console.ReadKey();
}
}
}
------解决思路----------------------
string json = @"{
""Alias"": ""[email protected]"",
""Name"": ""qwe"",
""Gender"": 1,
""SlaveList"": ""[email protected],[email protected]"",
""Position"": ""xx"",
""Tel"": """",
""Mobile"": ""12178879669"",
""ExtId"": """",
""PartyList"": {
""Count"": 1,
""List"": [{
""Value"": """"
}]
}
}";
string pattern = @"(?<=""SlaveList"":\s*"")[^""]*";
foreach (Match m in Regex.Matches(json, pattern))
{
Console.WriteLine(m.Value);
}
如果就你这点的话,不用反序列化,直接正则也可以