{"001":[{"level":"1","name":"a1","circle":"0","gender":"w","job":"8","head":"3.jpg"},
{"ll":"1","name":"a2","circle":"0","gender":"w","job":"8","head":"3.jpg"},
{"ll":"1","name":"a8","circle":"0","gender":"w","job":"a","head":"5.jpg"}],
"002":[{"ll":"1","name":"a3","circle":"0","gender":"w","job":"a","head":"0.jpg"}],
"003":[{"ll":"1","name":"a4","circle":"0","gender":"w","job":"a","head":"3.jpg"}],
"004":[{"ll":"1","name":"a5","circle":"0","gender":"w","job":"a","head":"5.jpg"}],
"005":[{"ll":"8","name":"a6","circle":"0","gender":"m","job":"a","head":"4.jpg"}],
"006":[{"ll":"28","name":"a7","circle":"0","gender":"w","job":"a","head":"3.jpg"}]}
如何循环得到比如001,和001里面的name的a1值,这两个值,然后002,和002里面的name的a3值,如何循环的解析
------最佳解决方案--------------------------------------------------------
string str = File.ReadAllText("D:\\1.txt", Encoding.Default);
var ary = Regex.Matches(str, @"""(\w+)"":\[.*?""name"":""([^""]+)""");
//要是版本低的话,用循环也行
foreach (Match m in ary)
{
Console.Write("序号:"+m.Groups[1].Value);
Console.WriteLine("name:" + m.Groups[2].Value);
}
------其他解决方案--------------------------------------------------------
json转为对象(System.Runtime.Serialization.Json、System.Web.Script.Serialization、Newtonsoft.Json),循环对象!
------其他解决方案--------------------------------------------------------
string str = File.ReadAllText("D:\\1.txt", Encoding.Default);
var ary = Regex.Matches(str, @"""(\w+)"":\[({.*?""name"":""([^""]+)""[^}]*}[,\]]\s*)+").Cast<Match>().Select(t => new { key = t.Groups[1].Value, name = t.Groups[3].Captures.Cast<Capture>().Select(tt => tt.Value).ToArray() }).ToArray();
这个获取了001和001里面的name三个值
------其他解决方案--------------------------------------------------------
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var data = { "001": [{ "level": "1", "name": "a1", "circle": "0", "gender": "w", "job": "8", "head": "3.jpg" },
{ "ll": "1", "name": "a2", "circle": "0", "gender": "w", "job": "8", "head": "3.jpg" },
{ "ll": "1", "name": "a8", "circle": "0", "gender": "w", "job": "a", "head": "5.jpg"}],
"002": [{ "ll": "1", "name": "a3", "circle": "0", "gender": "w", "job": "a", "head": "0.jpg"}],