日期:2014-05-17 浏览次数:20423 次
JavaScriptSerializer jss = new JavaScriptSerializer();
------解决方案--------------------
public static void Main() { string json = "{\"sign\":1,\"data\":"+ "{\"12400000\":{\"role_id\":12400000,\"role_name\":\"s1.\u8863\u53ca\u6cab\",\"role_level\":2}" + ",\"12400001\":{\"role_id\":12400001,\"role_name\":\"s2.\u8863\u53ca\u6cab\",\"role_level\":2}"+ ",\"12400002\":{\"role_id\":12400000,\"role_name\":\"s1.\u8863\u53ca\u6cab\",\"role_level\":2}}}"; var o = JObject.Parse(json); foreach (JToken child in o["data"].Children()) { foreach (JToken grandChild in child) { if (grandChild["role_name"].ToString().StartsWith("s2.")) { Console.WriteLine(grandChild["role_id"].ToString()); } } } Console.ReadLine(); }
------解决方案--------------------
sorry,忘了还要判断12400001
public static void Main() { string json = "{\"sign\":1,\"data\":"+ "{\"12400000\":{\"role_id\":12400000,\"role_name\":\"s1.\u8863\u53ca\u6cab\",\"role_level\":2}" + ",\"12400001\":{\"role_id\":12400001,\"role_name\":\"s2.\u8863\u53ca\u6cab\",\"role_level\":2}"+ ",\"12400002\":{\"role_id\":12400000,\"role_name\":\"s1.\u8863\u53ca\u6cab\",\"role_level\":2}}}"; var o = JObject.Parse(json); foreach (JToken child in o["data"].Children()) { var property = child as JProperty; if (property.Name.Equals("12400001")) { foreach (JToken grandChild in child) { if (grandChild["role_name"].ToString().StartsWith("s2.")