Details how to read JSON data in C # using Msscriptcontrol

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.