作者在原文中说明了通过C#调用Javascript来解析Json字符串的方法。代码如下:
using Microsoft.JScript; using Microsoft.Vsa; using Microsoft.JScript.Vsa; public static Dictionary<string, string> GetMyValue(string jsonSource, string key1, string key2) { Dictionary<string, string> dic = new Dictionary<string, string>(); string jsonStr = "function handleJson() {var j=" + jsonSource + ";var arr1=new Array();var arr2=new Array();for(var " + key2 + " in j." + key1 + ") arr1.push(" + key2 + "); return arr1;} handleJson(); "; object o = Eval.JScriptEvaluate(jsonStr, VsaEngine.CreateEngine()); ArrayObject arr = (ArrayObject)o; for (var i = 0; i <= (int)arr.length - 1; i++) { dic.Add(arr[i].ToString(), arr[i].ToString()); } return dic; } 本文转自齐师傅博客园博客,原文链接:http://www.cnblogs.com/youring2/archive/2012/10/12/2721776.html,如需转载请自行联系原作者