In the original article, the author explains how to use C # To Call Javascript to parse Json strings. The Code is as follows:
Copy codeThe Code is as follows:
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;
}
This is basically the case. Call js through C #, parse Json with Js, and convert the returned value to a C # array.