Here's a small piece to bring you a way to use Msscriptcontrol to read JSON data in C #. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.
There are already javascriptserializer classes in C # that can deserialize JSON data into objects
<summary>///JSON text-to-object, generic method///</summary>///<typeparam name= "T" > Type </typeparam>///< param name= "Jsontext" >json text </param>///<returns> object of the specified type </returns>public static T Jsontoobject <T> (String jsontext) {JavaScriptSerializer JSS = new JavaScriptSerializer (); Try{return JSS. Deserialize<t> (Jsontext);} catch (Exception ex) {throw new Exception ("Jsonhelper.jsontoobject ():" + ex. Message);}}
But lazy people like me do not want to define a class in advance, I just want to directly parse the JSON data sent by the client, or use Msscriptcontrol.scriptcontrol bar.
With the Eval method, you can do whatever you want.
Build ScriptControl Read the JSON data that the client passed over
Msscriptcontrol.scriptcontrol sc = new Msscriptcontrol.scriptcontrol (); SC. Language= "JScript"; SC. Addcode ("var jsonobject=" +data);//data is the JSON text submitted
Then can be based on the structure of the JSON with Eval, JS how to write how to write.
Such as
Sc. Eval ("JsonObject.content.length") SC. Eval ("Jsonobject.itemvalue")
To use Msscriptcontrol, you need to reference the COM component of Microsoft Script Control 1.0.