public void Test_GetJson() { string jsonp = @"jsonp({""a"":""1234"",""b"":9999})"; var json = "{\"a\":\"1234\",\"b\":9999}"; var result = Regexs.GetValue(jsonp, @"^\w+\((\{[^()]+\})\)$", "$1"); Output.WriteLine(result); Assert.Equal(json, result); }
/// <summary> /// 加载数据 /// </summary> /// <param name="data">数据</param> public override void LoadData(string data) { if (data.IsEmpty()) { return; } data = data.Trim().TrimEnd(';'); var json = Regexs.GetValue(data, @"^\w+\((\s+\{[^()]+\}\s+)\)$", "$1"); if (json.IsEmpty()) { return; } var jObject = JObject.Parse(json); foreach (var token in jObject.Children()) { AddNodes(token); } }