首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

100分求解,怎么获取一上字符串内的值

2013-01-23 
100分求解,如何获取一下字符串内的值如何获取一下例子中的各个值--PropertyProperty {background {flag

100分求解,如何获取一下字符串内的值
如何获取一下例子中的各个值


--Property
Property =
{
background = {flag=2,color={0,0,0},url="background.jpg"},
height = 92,
keep = {x = 10, y = 0},
recommend = {x = 480, y = 0},
search = {x = 570, y = 80},
searchText= {
x = 0,
y = 92,
height=73,
text = { "1","2","3"},
size = 38,
color = {54, 106, 162},
offsetX = 10,
spacing = 20,
}
}

要得到的结果是外层大括号内所有信息,注意总大括号中有包含其他大括号,该如何实现?
[解决办法]
把=替换成:
不就是json数据了吗?
用System.Runtime.Serialization.Json.DataContractJsonSerializer
或System.Web.Script.Serialization.JavaScriptSerializer
解析json数据就可以了
[解决办法]

            string str = File.ReadAllText("D:\\1.txt", Encoding.Default);
            var ary = Regex.Matches(Regex.Replace(str, @"^[^{]+{
[解决办法]
}[^}]+$", ""), @"(?is)([a-z]+)\s*=\s*{(((?<g>{)
[解决办法]
(?<-g>})
[解决办法]
[^{}])*(?(g)(?!)))}")
                .OfType<Match>().Select(t => new { name = t.Groups[1].Value, txt = t.Groups[2].Value }).ToArray();
         
[解决办法]
恩 ,解析成json 可能方便些!

热点排行